Reputation: 2887
I'm using Storyboards for a modal segue with a partial curl effect. Input fields are on the bottom, so if the keyboard is shown, it is necessary to translate the screen with:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.superview.center = CGPointMake(self.view.center.x, [[UIScreen mainScreen] bounds].size.height/2 - 200);
[UIView commitAnimations];
After its job is done, the finishing IBAction undoes the translation before dismissing the modal view:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
self.view.superview.center = CGPointMake(self.view.center.x, [[UIScreen mainScreen] bounds].size.height/2);
[UIView commitAnimations];
...
[self dismissViewControllerAnimated:YES completion:nil];
Everything alright with this but there remains the following problem: The user can always touch the opened curl to dismiss the view. If this is done while the keyboard is shown and therewith the screen is translated, the screen flickers shortly and an abnormal program behaviour is the result. I either need to deactivate the click-on-curl-to-dismiss-the-view or I have to perform the back translation before the curl dismisses. Neither using textFieldShouldReturn
to resign the first responder nor performing the back translation in viewWillDisappear
/viewDidDisappear
(which should in theory performed right before the dismiss?) have any effect. Does someone has any hint for me?
Upvotes: 1
Views: 345
Reputation: 9414
Create a protocol
/ delegate
on your destination modal view then call back to your presenting viewController
so your translation is handled properly once the view dismisses in the viewWillDisappear
method.
Here are some examples of delegates
Upvotes: 1