My iphone application has a user form under UIViewController.
When I out of application (go to background mode) and start application again some of my UIView changes its positions and sizes. (These UIViews depend on keyboard position)
Definately somewhere is my fault.
I try to figure what is going on when application starts again from background and where the UIView changes can be done.
May be you can suggest any links to read.
Thank you.
The UIViewController's viewDidLoad and viewWillAppear methods get called every time the view is dumped from memory, something that commonly happens when the app goes into the background. Depending on your code, it's possible that you're storing some position data that's not getting cleared. If that's the case, you can either:
Change your code to better fit the Model-View-Controller pattern so that the positioning code and variables are all in the controller, and you appropriately clean things up in its 'viewWillDisappearandviewDidUnload` methods (the better way), or
Clear out whatever remnants are hanging around in your application delegate's applicationWillEnterBackground method.
Related
I use a launchImage set to launch my app, instead of .xib. In AppDelegate.swift I set a NSThread.sleepForTimeInterval(2.0) to delay it, but when launchImage disappears, it doing so immediately.
What I would is that my launchImage disappears with a fade out effect. Is it possible?
Thanks
Strictly speaking, no, because you don't have control over how the OS uses the launch image.
But what you could do is make a dummy/replacement view of the same.
Upon launch, let the first UIViewController you load simply contain a UIImageView of the same launch image. You may have to do a little work to make it look right in your particular situation, for the interface orientation, etc. But if all goes right, when you load up this ViewController, you shouldn't notice a difference or any sort of transition between it and the actual launch instance -- visually it's all the same, tho technically it isn't.
Then you could have this view/image fade out. Essentially this gets the effect you want.
I am drawing with multiple colors by dragging fingers on the iPhone app but when I minimize the app and then maximizes, I am losing all my drawing as it calls the drawrect method. I don't know from where this method is being called but I am not able to see any solution to this problem. Mainly it is happening when I am running many apps on the device. I think the iOS deletes all the data in the buffer in order to prevent low performance of the iPhone. What is the solution to this issue? And why it is losing the drawing? Please help! I didn't find any solution of this problem.
Because your view is unloaded in the background , and when you are back to the foreground , the view will be recreat , so it will redraw.
When you enter background , if the device memory is low , Apple will unload the background app`s view(even close your app) , to enlarge the memory for the current running app. Your view is unloaded , when you be back to foreground , the view will recreat by the "data" , so make sure do not hold the "data" in the view.
And maybe in IOS6 , Apple modify the mechanism
I am losing all my drawing as it calls the drawrect method.
From your Question, it seems as if you are not drawing in your drawRect method,
drawrect method is called every time your view is updated / loaded. So when you enter from background drawrect method is called. If you are not handling in your drawing mechanism in drawrect method, you loose all data.
Apple States that
The default implementation of this method does nothing. Subclasses
that use native drawing technologies (such as Core Graphics and UIKit)
to draw their view’s content should override this method and implement
their drawing code there. You do not need to override this method if
your view sets its content in other ways. For example, you do not need
to override this method if your view just displays a background color
or if your view sets its content directly using the underlying layer
object. Similarly, you should not override this method if your view
uses OpenGL ES to do its drawing.
If you are handling it other ways then you need to handle that after your view is drawn on in viewwillAppear.
Else there can be memory reason, since if you get memory warning, ViewDidLoad is called where you generally initialise data.
The framework will call drawRect as needed, it is your responsibilty to draw the view when it is called. You should be storing whatever state you need from the users actions in order to redraw the view whenever drawRect is called.
This question seems to get asked a lot but I have never found a definitive answer as to whether or not it's possible to have custom transitions the same way UIKit does.
I know you can do tricks like take a screenshot of the current view and the upcoming view, and then animate those while you change view controllers under the animation. However, this takes quite a bit of memory, as you have basically 2 full extra screens worth of drawing (because of the screenshots).
I'm looking for a more elegant way of presenting view controllers with a custom animation. Or, is there a more memory-efficient way of doing the above approach?
There are several ways to accomplish this, depending on how you want to transition, whether your controllers are embedded in a container controller, etc. In the simplest case, where you have a single controller, and you want to transition to another controller, you can do it with the following steps:
instantiate the new controller (lets call it B, and the original one A)
add B's view as a subview of the window (gotten from self.view.window)
set B's frame to be off screen in which ever direction you want or make its alpha 0, or make it have zero size, depending on what kind of transition you want.
do what ever transition you want with animateWithDuration:animations:completion:
remove A's view (in the completion block)
in the completion block, make B the root view controller of the window
Essentially you're having the system automatically retain and release, along with do whatever is happening below the calls rdelmar's answer outlined. Transitioning a view controller is just animating a view while having the system keep your controller in memory.
But, to answer more of your questions, UIView animations create duplicates and cache the images, too. (Btw, the system cache doesn't unload its memory, so avoid UIImage imageNamed.
You will probably want to code it yourself using a timer if you want efficiency, and drum up all the graphics tricks you can think of.
And never, ever trust iOS to work the same way it did the last version. Everything I said is subject to being wrong the same way iOS 6 broke retain on annotating, and the manuals stated iOS 3 animations will become obsolete (and are now replaced instead?) gah, just saying be careful with efficiency, it may be broken or updated in the somewhat distant future if you try it.
I am working on an App built with Xcode 4.1 and linked against iOS 4.0. Today I have started testing on iOS5 to get it ready by the time the new OS launches.
We have an interesting issue where almost every UIView subclass animates when they are redrawn. The views returned as section headers of a table view are animated every time the user scrolls for instance. But practically almost any UIView update is animated. The effect on the screen is very disorienting.
I can't find anything on this issue. But I must be missing out on some big changes or doing something very wrong.
Anybody experiencing similar issues?
Based on what I've seen of iOS 5 this isn't normal behavior.
It sounds like you are wrapping some call to that TableView inside of a UIView animation block, so any call the UITableView makes (Such as LayoutSubviews) is also in that animation block. Another possibility is that you forgot to properly commit an animation, so all UIView changes past that are also included.
There have been some changes to UIView animations and the way they are run. Just anecdotally, I've had some trouble with Animations that used to run sequentially running on top of each other. So, maybe this is a bug in your code that was just never noticeable before.
I'm looking for advice about a nib that's very slow to load. It's big and complex, with lots of subviews and doodads. When I fire my UINavController to push it, it's noticeably laggy (maybe almost a second) on my 3G. It sits there with the table cell selected and nothing else happening for long enough to make you wonder if it's broken.
I wonder about pre-loading it in another thread while the user is on the previous view. I could probably fire the selector in the background with a delay in the previous view's viewDidAppear, and then keep it in a property until push time comes.
Thoughts?
Can you split the subviews and doodads into their own, smaller nibs? Then you don't have to load everything at the same time, just what you need for when you need it.
I am working on a project, which is so full of the same, it would be unusable in NIB form. I choose to start creating my own sub-views in code, and then in performance concern areas, did my own drawing (like you would in a complex/custom UITableViewCell implementation).
It isn't really that hard to create some or all of your elements in code, or roll areas of them up to something that can be drawn by hand.
Just a thought.
I would be careful about assuming that it is the loading of the NIB file which is slowing you down. Run Instruments and / or Shark against your application, focusing on sampling what happens when you tap on the table to bring up your new view. You might be surprised at where the bottleneck is. In particular, it might not be loading the NIB itself, but something in the initialization methods of one or more of the subviews.