19th September 2013

-viewWillAppear: on iOS7

Guides | Tutorial By 3 years ago

The swipe from left to go back interaction newly added in iOS7 can be a bit of a pain to code to in the beginning…

Because you interact via a drag, the user can choose to cancel going back and drag it back to it’s original position. Behind all this, -viewWillAppear: is still called on your other view controller. Some developers may first encounter some strange bugs when they use the new interaction compared to the old tap back button action, most likely from code that is expecting something to definitely happen but it never does.

At WWDC this year, even the Apple engineers joked around a bit saying it would have been more appropriate if it was now named -viewMightAppear:. Some also mentioned a couple of their apps broke because of the view controllers expecting something which never happened, so you’re not alone 🙂

When -viewWillAppear: is called, you may want to check if it is because of a drag interaction or from the back button being tapped. It is very simple to do:

- (void) viewWillAppear:(BOOL)animated
	[super viewWillAppear:animated];

	const BOOL isInteractivePop = (self.navigationController.interactivePopGestureRecognizer.state == UIGestureRecognizerStateBegan);

		//	Interactive pop stuff
		//	Back button stuff
Recommended Posts

Disabling 'slide from left' back button in iOS7

Post by 3 years ago

In iOS7, if a user wants to go back a page they can now choose between using the old back button or a newly introduced method by dragging from the left side of the screen....

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!