0

I added a modalView to my App, everything working fine, but on closing the modal, the whole modalView jumps about 1-2 centimeters to left while it disappears.

I did not find any reason for it yet, so here is the code regarding modal:

AppController:

- (void) showNameModal:(Player *)player 
{
    namesModal = [[PlayerModalView alloc] init];
    namesModal.delegate = self;
    namesModal.player = player;

    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:namesModal];

    navCon.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:navCon animated:YES];

    [navCon release];
    [namesModal release];
 }

 - (void)didDismissModalView 
 {
    [self dismissModalViewControllerAnimated:YES];
 }

ModalView:

 - (void)dismissView:(id)sender 
 {
    [delegate didDismissModalView];
 }

called via navigation buttons as well ass via keyboard by

  [self dismissView:nil];

As you can see, there is nothing special in it, could be taken from a manual actually. What happens in detail:

Modal appears in center of screen, slides in from the bottom. centered all time. i can handle some actions in the modalView, it stays centered.

now, dismissing the view makes it jumping to the left, than slides out.

Since it's a forced landscape-right app (currently), I was only able to notify the left-jump.

Any ideas how to get this jumping away?

Thanks

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
thedanielhanke
  • 730
  • 1
  • 6
  • 22

4 Answers4

0

The problem is that the UIViewController you're showing modally doesn't allow the orientation you're presenting it in, so when it disappears, it will do that in a direction that it considers "allowed".

Add this to the UIViewController for you modal view:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
Andreas Ley
  • 9,109
  • 1
  • 47
  • 57
0

Try this,

- (void)didmissView:(id)sender
{
   [self.navigationController didmissModelViewControllerAnimated:YES];
}
AechoLiu
  • 17,522
  • 9
  • 100
  • 118
  • oki, that crashes the app, *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller.. so i guess i oversee something.. – thedanielhanke Sep 20 '10 at 11:54
  • I remember ModelView should dissmiss itself. The one who present the modelView has no responsibility to dismiss the modelView. But I feel strange, why does the one who present the modelView become nil ? – AechoLiu Sep 20 '10 at 21:41
0

You are not modally presenting an instance of PlayerModalView but rather a UINavigationController. The left jerk you see is most likely the default animation of the navigation controller attempting a slide transform to the (non-existant) previous view.

It doesn't sound like you need a navigation controller for the PlayerModalView. Instead, you should create an ordinary view controller for it.

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • the PlayerModalView actually should have a Navigation-Bar, therefore i`d choose a UINavigationController. However, what do you mean by "(non-existant)" ? – thedanielhanke Sep 21 '10 at 09:05
  • It turns out, that its an orientation problem. only on 3.2.2, 4.2 works fine. Simulatorresults differ completely from Hardware too.. Thank you a lot anyways! – thedanielhanke Sep 21 '10 at 09:43
0

This solution seems to work well: Modal View Controller with keyboard on landscape iPad changes location when dismissed

To simplify resigning the first responder (if finding it is difficult), you can just call

[self.view endEditing:YES];
[self dismissModalViewControllerAnimated:YES];
Community
  • 1
  • 1
Alex Pretzlav
  • 15,505
  • 9
  • 57
  • 55