- (IBAction)pop:(id)sender {
UIViewController *viewController = [[UIViewController alloc] init];
// view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 130)];
view.backgroundColor = [UIColor yellowColor];
viewController.view = view;
[view release];
[self presentModalViewController:viewController animated:TRUE];
[viewController release];
}
以上的代码中,在initWithFrame方法中,我不管把view的frame属性设置成什么,最终效果,这个弹出的控制器视图都是全屏的。所以我有些迷惑了,到底是什么过程改变了这个view的frame属性呢?
我在stackoverflow上问了这个问题,那老外的回答我还是没有找到有用信息呢。
http://stackoverflow.com/questions/10820037/how-did-ios-set-uiviewcontrollers-view-frame-before-shown
kejinlu
2012-05-31 01:02:49 +08:00
[self presentModalViewController:viewController animated:TRUE]; 不过这个方法目前的状态为DEPRECATED,建议使用新的吧,所看看苹果的文档。
presentModalViewController:animated:
Presents a modal view managed by the given view controller to the user. (Deprecated. Use presentViewController:animated:completion: instead.)
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Parameters
modalViewController
The view controller that manages the modal view.
animated
If YES, animates the view as it’s presented; otherwise, does not.
Discussion
* On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property. *
Sets the modalViewController property to the specified view controller. Resizes its view and attaches it to the view hierarchy. The view is animated according to the transition style specified in the modalTransitionStyle property of the controller in the modalViewController parameter.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/37896
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.