2

I have a view controller whose job is to display a large image, initially sized to fit the screen, which the user can pan and zoom. The image was taken with phone's camera, then saved to the device and reloaded using +[UIImage imageWithData:].

I show the controller in a navigation stack, but I use a fading transition like this:

SGBImageController *imageController = [[[SGBImageController alloc] init] autorelease];
imageController = <theImage>;
[imageController loadView];

[UIView transitionWithView:self.navigationController.view
                  duration:0.33
                   options:UIViewAnimationOptionAllowAnimatedContent
                          |UIViewAnimationOptionTransitionCrossDissolve
                animations:^{

    [self.navigationController pushViewController:imageController animated:NO];

} completion:nil];

The fade animation should be smooth, but it's jerky, and looking in instruments I see it's spending all its time in CA::Layer::Render. I've added the loadView line to try to force it to show its view, but it hasn't helped. How do I make a view controller draw itself before it is animated?

Simon
  • 25,468
  • 44
  • 152
  • 266

1 Answers1

0

You shouldn't call loadView directly, thats something that the OS handles. Instead, just referencing imageController.view in any way will start the loading. You can use a delegate callback or NSNotification to notify your class when SGBImageController's viewDidLoad method is called, and then from there begin your animation.

Chris C
  • 3,221
  • 1
  • 27
  • 31
  • That's not true. You use viewDidLoad if you're using a nib, but I don't use nibs. If you want to construct the view yourself, you use viewDidLoad. – Simon Feb 08 '13 at 07:07
  • Yes you can override loadView if you don't load the view from a Nib, but you dont have to directly call the method. Source: http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/loadView – Chris C Feb 08 '13 at 17:47
  • True. But you'll also get a warning if you call [imageController view] without doing anything with it, whereas [imageController loadView] is more expressive. – Simon Feb 08 '13 at 18:29