【发布时间】:2011-09-29 22:04:38
【问题描述】:
我的模态 UIViewController 中的背景在动画开始之前显示 时遇到问题。我有一个简单的 UINavigationController 加载 UIViewController。然后我通过从下方向上滑动的 presentModalViewController 调用呈现 UINavigationController。在 UIViewController 的 loadView 方法中,我设置了标准的 self.view 并创建了一个背景 UIImageView。此背景加载,但仅在模态动画完成之后。我以前做过很多次这类事情,记得曾经遇到过这个问题,但我一生都找不到我的“神奇”解决方案。
我的代码如下:
PhotoVideoViewController *photo = [[PhotoVideoViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:photo];
NSLog(@"start present modal view controller");
[self.navigationController presentModalViewController:nav animated:YES];
[photo release];
[nav release];
PhotoVideoViewController 加载视图:
- (void)loadView {
UIView *myview = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = myview;
[myview release];
NSLog(@"background loading");
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-main.png"]];
background.frame = CGRectMake(0, -45, 320, 480);
[self.view addSubview:background];
[background release];
}
“开始当前模式视图控制器”显示在日志中之前“后台加载”日志显示,这告诉我明显有问题。我试图把[照片发布];在 presentModalViewController 之前,但它确实不解决了问题。
我也在这里完成了我的研究,其他帖子都没有回答我的问题:
UINavigationController with presentModalViewController
UINavigationController and presentModalViewController
- 这两种方法都适用于将 UINavigationController 用作其中包含 UIViewController 的模态屏幕的正确方法。
非常感谢任何帮助。我已经尝试了几种排列并且不知所措。它的顺序是正确,但我的代码显然没有得到完美的顺序。
提前谢谢你!
J
【问题讨论】:
标签: uiviewcontroller uinavigationcontroller background presentmodalviewcontroller loadview