1

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?

RyuX51
  • 2,779
  • 3
  • 26
  • 33
  • Have you tried adding the dismissViewControllerAnimated to the completion block of a animateWithDuration animation block? That way it only happen after your superview.center is called. – Mark McCorkle May 21 '13 at 13:53
  • When touching the curl there is no manual `dismissViewControllerAnimated` I could add there. – RyuX51 May 21 '13 at 14:18

1 Answers1

1

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

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • My problem is that there is no `[self dismissViewControllerAnimated:YES completion:nil];` I could delay. The IBActions are working just fine. But if the user touches the curl the modal view dismisses itself without giving me the time to make my translation. (I tried your code inside my `viewWillDisappear` though. As expected it didn't prevent the flicker and the malfunction.) – RyuX51 May 21 '13 at 14:15
  • It sounds like you are needing a delegate to handle the callback in viewWillDissapear so your previous view translates back down. – Mark McCorkle May 21 '13 at 14:22