1

Same code as in a previous question, but a different issue.

I've created a custom animation to add a view controller to a UINavigationController. This code scales a view to 80% the original size, then flips it, then scales it back up to its original size:

[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
    // Scale the controllers' views down.
    self.view.transform = CGAffineTransformScale(self.view.transform, 0.8, 0.8);
} completion:^(BOOL finished) {
    // Transition to the new view and push on the new view controller.
    [UIView transitionWithView:self.view duration:1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        [self pushViewController:viewController animated:NO];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveLinear animations:
^{
            // Scale back to the original size.
            self.view.transform = CGAffineTransformScale(self.view.transform, 1.25, 1.25);
        } completion:nil];
    }];
}];

The issue is that, when the animation completes, the new view is displayed very nicely, except that it is drawn under the task bar. That is, it draws in at screen origin 0,0, rather than 0,20. The "Status Bar" option is set in IB (to "Black"), and, naturally, this does not happen if I use a standard UINavigationController push animation, only my custom one. If I rotate the device after the animation, the redraw on rotation moves it to the proper place. But how do I get it to do that in the first place?

As an added wrinkle, it does not draw under the task bar if I move the pushViewController:animated: call a line down to the completion: block (though then the view appears to flip to itself and then suddenly show the new view, of course).

Community
  • 1
  • 1
theory
  • 9,178
  • 10
  • 59
  • 129
  • When scaling back to original size, just set `self.view.transform = CGAffineTransformIdentity;`. The identity transform is always unscaled and unrotated. – David Rönnqvist May 24 '12 at 05:07
  • Thanks. Tried that, makes no difference. – theory May 24 '12 at 05:09
  • Also, as danyowdee asked in your previous questions: "Couldn’t you just use `presentViewController:animated:completion:` setting its transition style to `UIModalTransitionStyleFlipHorizontal`?" – David Rönnqvist May 24 '12 at 05:18
  • Yes, but then it would not be the custom animation designed by my designer partner, which is cool and all, you know? – theory May 24 '12 at 05:19
  • @DavidRönnqvist Oh, and also because UIModalTransitionStyleFlipHorizontal is for modal transitions. This is a UINavigationController push. – theory May 31 '12 at 05:09
  • I got hit by the exact issue, did you solve this problem @theory? – Robert Mao Sep 26 '12 at 06:15

1 Answers1

0

I found the only work around so far is hide the navigationbar and then show it.

after you set your transform, add following 2 lines:

[self setNavigationBarHidden:YES];
[self setNavigationBarHidden:NO];

It's ugly but works, I am also looking for a better solution.

note: layoutsubview, setNeedsLayout won't work.

Robert Mao
  • 1,911
  • 22
  • 24
  • Nice! I had to abandon this code path, but I will get back to it eventually, and hope that your solution works! I bet it does (it makes sense!), so will accept it. – theory Sep 28 '12 at 07:02