Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

uinavigationcontroller - Navigation stack becomes unusable after canceling iOS 7 back swipe gesture

I am running into an issue where my navigation controller becomes unusable after initiating then canceling the new iOS 7 back swipe gesture.

Some relevant information:

  • My app has a home page with various activity pages.
  • The home page hides the navigation bar in viewWillAppear
  • The home page un-hides the navigation bar in viewWillDisappear

    -(void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        // Let's hide the navbar when we show the home view
        [self.navigationController setNavigationBarHidden:YES];
        …
    }
    
    -(void) viewDidDisappear:(BOOL)animated 
    {
        [super viewDidDisappear:animated];
    
        // Let's hide the navbar when we show the home view
        [self.navigationController setNavigationBarHidden:NO];
    }
    

When a user taps a activity icon on the home page the view controller for the activity is pushed onto the stack.

If a user starts to use the new back swipe gesture in iOS but then stops the gesture (i.e. decides not to go back) everything looks ok. However, if a user causes another view controller to get pushed on the nav stack the nag bar then becomes unusable and the user can not navigate back from the current view controller.

Notes

  • It only happens when I show/hide the navigation bar
  • I can still slowly perform the back gesture and everything will work fine as long as I don't cancel the gesture
  • The nav bar seems like it will work but hitting the back button doesn't pop the view controller.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure if you already resolved this but I'm facing the same issue but with one difference. The navigation stack only messes up if I setAnimated to NO.

So this works:

[self.navigationController setNavigationBarHidden:YES animated:YES];
...
[self.navigationController setNavigationBarHidden:NO animated:YES];

but this doesn't:

[self.navigationController setNavigationBarHidden:YES animated:NO];
...
[self.navigationController setNavigationBarHidden:NO animated:NO];

If you really want animated to be NO for whatever reason, one work around is to set alpha to 0/1 instead of hiding/unhiding the NavigationBar:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.alpha = 0.0f;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setAlpha:1.0f];
}

The downside is that there's no nice slide-to-pop transition animation. If you did find a better way, do let us know.

UPDATE: This is now old but I solved my issue by not ensuring that whatever state is changed in current view's viewWillDisappear, is restored in viewWillAppear. Don't tear down things in viewWillDisappear that you can't setup again.

This is what happens when you cancel the pop animation:


  1. Current viewWillDisappear
  2. New viewWillAppear
  3. [cancelled... reverses]
  4. New viewWillDisappear
  5. New viewDidDisappear
  6. Current viewWillAppear
  7. Current viewDidAppear

I guess in this brave new world, viewWillDisappear/viewWillAppear does not always mean view "will" disappear/appear :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...