presentModalViewController将新视图向上方滑动并超出屏幕顶部 [英] presentModalViewController slides a new view too far up and goes above the top of the screen

查看:221
本文介绍了presentModalViewController将新视图向上方滑动并超出屏幕顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我有一个splitViewController设置,这可能是引起某些问题的原因.在详细信息视图控制器中,我有一个按钮,单击该按钮时将调用上面的代码.

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.

问题是,当它向上滑动屏幕后,它会继续滑动经过它应该停止的位置,最后停止向上移动10-15像素.基本上,该模式视图向上滑动的程度很大,以至于视图的很大一部分位于屏幕顶部上方.同时,相同数量的空间是屏幕底部的空白区域",这进一步表明该视图只是向上移动太远了.

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?

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

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

抱歉,我打算在那输入navCon.我已将其固定在上面.

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

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

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

解决方案:

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

经过反复试验,我意识到我从未真正设置过视图的框架!如此简单的解决方案...我一直在浏览包含.xib文件的示例,由于这些文件是自动创建框架的,所以我完全忽略了它!

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

推荐答案

尽管我已找到问题中所述的快速解决方案.事实是,仍然存在许多问题.经过进一步检查,我呼吁appDelegate调用以下方法:

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

基本上,我有一个称为模式视图的根视图类,它解决了我所有的问题.显然,从splitview的详细视图中调用模式视图与从根视图(恰好是splitViewController)调用模式视图不同.我希望这对将来的任何人有帮助.干杯.

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-推送模态视图

这篇关于presentModalViewController将新视图向上方滑动并超出屏幕顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆