popping ViewController with swipe only works once - objective-c

If you implement the popViewController:animated: method like this:
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
return [super popViewControllerAnimated:NO];
}
on a navigation controller, the swipe back gesture only works one time. On the next swipe it won't do anything. Additionally, if you hit the back button then, the view controller will be popped with an animation.
Is this a bug or am I missing something?
Feel free to try this for yourself: https://github.com/mrmoneyboy/UINavigationController-Tests

Related

How to call viewWillAppear with storyboard iOS7

I'm using storyboard.
As I remeber (I worked with ios 4, long time ago=)) everytime, when View appears, calls
-(void)viewWillAppear:(BOOL)Animated {}
method.
Now this method doesn't call, if I press Home button and run app again.
How to fix it?
I need to update one UIView if it appears after home pressing.
The function viewWillAppear is not part of UIView. It is part of UIViewController.
It is called after the view controller's view has been loaded and just before it starts to transition onto screen.
If you create a subclass of UIView and put this function in it then it will never be called because it isn't supposed to be.
Edit
You are correct that viewWillAppear does not get called when the app is coming back from the background.
If you want to update a part of your app when this happens then you can do something in the AppDelegate.
I'd recommend not trying to store properties etc... in the AppDelegate though. You should do something like this...
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
// just pass the message on. In your view you will need to add an observer for this notification
[[NSNotificationCenter defaultCenter] postNotificationName:#"UpdateViewNotification" object:nil];
}
try this, call the super,
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

UIViewController is in wrong orientation when performing navigation controller pop animation

I am using the new iOS8 viewWillTransitionToSize in my view controller like so:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
__weak typeof(self) weakSelf = self;
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[weakSelf handleOrientation:[UIApplication sharedApplication].statusBarOrientation];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}
I am handling rotation changes in the transition block. This works fine.
But if I push another controller on. Rotate the device. Then navigate back using the swipe from the left of the screen pop gesture (interactivePopGestureRecognizer). The view is in the wrong orientation until the pop gesture is complete. If I just pop the controller using a button, the view is in the correct orientation. Also if I move the handle orientation into the completion block, this also works. But on normal rotation there is now no animation.
Here is a link to an example project
https://drive.google.com/file/d/0B_Fq1pK7MmAzWm5TUGRuX0R3Nlk
Steps:
Select an iOS 8 device
Push to the second view controller using the button
Rotate the device
Navigate back using the swipe gesture
The view will be orientated wrong.
Anyone encountered this problem before? It seems like a bug.

UIScrollView scrolls to different position while animating presentation of modal view controller

I'm using a UIScrollView for paging three different UIViewControllers. The pager initializes to display page 1 from start. So the user can swipe left or right from the beginning. When I present a modal view controller from the mid view controller, the UIScrollView temporarily scrolls to the first page during the animation of the presented view controller. When I dismiss the modal view controller everything's back to normal and the UIScrollView displays the center view controller.
I would expect (and want) the UIScrollView to keep it's position during the animation.
This is not a technical bug that causes a crash or something, it's just ugly.
Anyone ever had that before? Any idea how to fix it?
I've had this same problem, and after much investigation it appears to be a bug in UIKit relating to scrollviews and AutoLayout. Here's the 'fix'...
In viewDidDisappear:, save the current scrollview contentOffset to a property, and reset it to zero:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.previousContentOffset = self.scrollView.contentOffset;
self.scrollView.contentOffset = CGPointZero;
}
Then, in viewWillAppear:, reset the content offset back to what it was previously. I had to dispatch this onto the main queue to get it to work correctly:
- (void)viewWillAppear:(BOOL)animated
{
if (!CGPointEqualToPoint(self.previousContentOffset, CGPointZero))
{
dispatch_async(dispatch_get_main_queue(), ^{
self.scrollView.contentOffset = self.previousContentOffset;
});
}
}

Is there a way to remove UITabBar/or do something for a UIViewController and ALL other UIViewcontroller added on top of UINavigationBar Stack?

This is the approach I am using:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.tabBarController hideTabBar];
}
-(void) viewWillDisappear:(BOOL)animated
{
[self.tabBarController showTabBar];
[super viewWillDisappear:animated];
}
With this approach if I add something to the navigation stack the UITabBar will be shown again.
What about if I want UITabBar to be only shown when user navigate away to another tab or press back button, so not all cases of viewWillDisappear?
Pushing a UIViewController on top of navigation stack shouldn't change that
You can use NSNotification as well, so whenever you require to hide tab bar. At that moment fire that notification which will show/hide your tab bar.
Benifit of NSNotification is, you can fire that in entire application life cycle, and it does not be specific to any view controller or any class. One can use that independently from any class/view controller.
Hope this is what you are looking for.
Regards,
Mrunal
Do following in your view will appear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.tabBarController.tabBarController.tabBar.hidden=TRUE;
}
This will remove tabbar from the particular controller . and navigation stack will not change.
This is what I did
At viewDidDisappear, I check if self.navigationController is empty. If it's empty I simply know that the view has been poped out of navigationController, which is the only way to get that view out of window hierarchy.

Calling dismissModalViewController in UISplitView causes rotate to portrait mode

I am presenting a UIModalView in a UISplitViewApplication. I have wired up a "done" action, which is:
- (IBAction) donePressed:(id) sender
{
[self dismissModalViewControllerAnimated:YES];
}
When I press the button, the orientation of the device changes to potrait mode. Why is this?
I don't think you've provided enough code for anyone to be able to give you an accurate answer, but one possibility is that you haven't implemented the following method in all of your controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
I had this problem and the accepted solution didn't solve it for me.
I was trying to load a modal view controller from a UIPopoverController, and every time it was dismissed it would rotate to portrait.
When I moved the modal view to load from the Detail View Controller of the UISplitView it worked fine.