24

When I am trying to modal a view controller with flip horizontal transition in iOS7, the origin of navigation bar is (0, 0) at beginning and then jump to the right position at (0, 20). Is it possible to make it behave the same with in iOS6? You can download the project here.

I have created a customized navigation bar as following:

@implementation MyCustomNavigationBar

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    UIImage *image = [UIImage imageNamed:@"Custom-Nav-Bar-BG.png"];


    [image drawInRect:CGRectMake(0,  0, self.frame.size.width, self.frame.size.height)];

    if (IOSVersion <7) {
    }else{
        self.translucent = NO;
        self.tintColor = [UIColor whiteColor];
        self.barStyle = UIBarStyleDefault;
        self.barTintColor = [UIColor redColor];

    }
}

@end

Any help will be appreciated.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
lu yuan
  • 7,207
  • 9
  • 44
  • 78

3 Answers3

57

I have the same problem with you. I think It's a bug with UIKit on iOS 7.

I added a little of code at viewWillAppear method on presentation

     [self.navigationController.navigationBar.layer removeAllAnimations];

When I dismiss this view, I added:

-(IBAction)btnDonePressed:(id)sender {
    [UIView transitionWithView:self.navigationController.view
                      duration:0.75
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:nil
                    completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
}

This worked for me. Hope this helps you.

Thanh Vũ Trần
  • 792
  • 6
  • 15
  • 2
    This also works for a segue that is presenting a modal `UINavigationController` via a flip animation. I added the `UIView` transition above with `UIViewAnimationOptionTransitionFlipFromRight` option to prepareForSegue and it fixed the rest of my issues with this bug. I will be submitting a radar for this w/ a sample project. – Matthew Crenshaw Nov 06 '13 at 21:15
  • Perfect. Should be noted though, the first fix (on viewWillAppear) is for preventing the bump on the displayed modal view, the second fix is for preventing the bump when returning to original view. – HyBRiD Dec 26 '13 at 09:58
  • On the second fix, for returning to the original view, you may need to test for device orientation to avoid conflicting animations. E.g. ````if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))...```` – Michael J. Jan 12 '14 at 22:38
  • this fix works well for 4" devices, but still get a bump on return when 3.5" device. – wkhatch Mar 04 '14 at 08:22
  • can u explain how to use if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) in original view – mychar Mar 24 '14 at 04:07
  • this sort of works. it reduces the effect but it's still there though subtle. – glasz Apr 03 '14 at 23:52
  • Can anyone verify that the default flip animation duration is actually 0.75? Seems like it also be 1.0 or a number of values in that range. Thanks! – James May 13 '14 at 15:43
  • I have to modal views in the app I'm working on; both are dismissed with the flip animation. However, only one of them does the annoying navbar jump. In other words, I think it has to do with how the view is setup, and not a bug in iOS 7. So, a "native" fix should be possible. – Johan Aug 05 '14 at 10:26
  • I am transitioning from a `UINaviagtionController` (navigation bar hidden; hosts my login view) to a `UITabBarController` that has a `UINavigationController` (navigation bar showing - this is my app's main screen) on the selected tab, and was experiencing this issue. Removing the animations solved it, but Why are there any animations attached to the navigation bar in the first place? I would like to have a cleaner solution than having to add that code to the `-viewWillAppear:` method of the top view controllers for ALL my tabs! – Nicolas Miari Aug 13 '15 at 07:01
  • 1
    @NicolasMiari, it seems Apple fixed this issues. I don't have the problem on iOS 9. About your question, I guessed Apple attached some animations to change presenting view's frame after detecting. For more information about navigation bar on iOS 7, you can read this http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on. I don't have a cleaner solution, this answer is only my solution. Sorry. – Thanh Vũ Trần Oct 27 '15 at 06:37
4

Instead of hacking [navigationBar.layer removeAllAnimations];, something like this should work as well:

[UIView transitionWithView:self.view.window duration:FlipDuration options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
    [UIView performWithoutAnimation:^{
        [self presentViewController:modalController animated:NO completion:nil];
    }];
} completion:nil];
Vadim
  • 9,383
  • 7
  • 36
  • 58
3

Just give the -20 in the xib in option "ios 6/7 Deltas"

or read this

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/index.html#//apple_ref/doc/uid/TP40006556-CH66-SW1

virantporwal
  • 989
  • 2
  • 6
  • 26
  • I have tried to set the "ios 6/7 Deltas" of the navigation bar, but without help. Have you tried too? – lu yuan Oct 04 '13 at 18:05
  • These answers gave me some point, and I have worked around it, but failed to solve the problem. – lu yuan Oct 05 '13 at 16:03
  • I see your demo but its working fine here is values:- self.frame.size.height :44.000000 version==7 rect.size.height :44.000000 self.frame.size.height :44.000000 Test[430:a0b] version==7 rect.size.height :44.000000 – virantporwal Oct 08 '13 at 05:55
  • the frame value is correct, but the transition is weird, much different with in iOS6. – lu yuan Oct 08 '13 at 12:08
  • 1
    Can you leave me your email? Then I can send your the record video of the transition. – lu yuan Oct 08 '13 at 12:09