presentModalViewController slides a new view too far up and goes above the top of the screen

两盒软妹~` 提交于 2019-12-12 01:32:47

问题


-(void)reviewClicked:(id)sender
{
    ReviewViewController *newView = [[ReviewViewController alloc] init];
    newView.delegate = self;
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView];
    [self presentModalViewController:navCon animated:YES];
}

I have a splitViewController setup, which is what is probably causing some issues. Within the detail view controller, I have a button that when clicked calls the above code.

The goal is to slide a view from the bottom of the screen upwards so the user can review their selections, and then click a button to return back to the original detail view. This code is working and you can click back and forth between the modal view and original detail view.

The problem is, after it slides up the screen, it continues sliding past where it should stop, and finally stops a good 10-15 pixels too far up. Basically, this modal view slides in so far up that a good chunk of the view goes above the top of the screen. Meanwhile, that same amount of space is "empty black space" at the bottom of the screen, just further suggesting that the view just simply moved too far up.

Complicating matters, it slides in just fine in landscape mode.

So the question is, does anyone know why this bug is occurring to make the modal view slide too far up and past the top of the screen?

-=-=-=-=-=-=-

Edit: Sorry about that, I meant to type navCon in that spot. I fixed it above.

-=-=-=-=-=-=-

Solution:

-(void)reviewClicked:(id)sender
{
    ReviewViewController *newView = [[ReviewViewController alloc] init];
    newView.delegate = self;
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView];
    navCon.view.frame = CGRectMake(0, 0, 768, 1080);
    [self presentModalViewController:navCon animated:YES];
}

After some trial and error, I realized I had never actually set the frame of the view! A solution as simple as that...I had been running through examples that included .xib files, and since those files created the frame automatically, I totally overlooked it!

Keep in mind for anyone looking at this in the future. This frame is for portrait mode only. If you want landscape mode, just modify the frame accordingly:

navCon.view.frame = CGRectMake(0, 0, 1080, 768);

回答1:


Although I had found a quick solution to the problem as described in the question. The fact is, there were many problems still around. Upon further inspection, I called upon the appDelegate to call these methods:

[self.splitViewController presentModalViewController:navCon animated:YES];
[self.splitViewController dismissModalViewControllerAnimated:YES];

Basically, I had the root view class call the modal view which solved ALL of my issues. Apparently calling a modal view from within the detail view of a splitview is NOT the same as calling a modal view from the root view (which happens to be the splitViewController). I hope this helps anyone in the future. Cheers.

-=-=-=-=-=-=-=-

For more reference, see this post I stumbled upon:

UISplitViewController - Pushing Modal View



来源:https://stackoverflow.com/questions/10144144/presentmodalviewcontroller-slides-a-new-view-too-far-up-and-goes-above-the-top-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!