开发者

iPad/iOS modalView jumps left on dismiss

开发者 https://www.devze.com 2023-01-17 00:20 出处:网络
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 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


Try this,

- (void)didmissView:(id)sender
{
   [self.navigationController didmissModelViewControllerAnimated:YES];
}


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.


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];


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消