gpt4 book ai didi

ios - iOS 在显示之前如何设置 ViewController View 框架?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:25 25 4
gpt4 key购买 nike

我不熟悉 iOS UIViewController 的详细实现。我有以下代码来创建一个新的 UIViewController 并显示它,但是我在 initWithFrame 方法中设置的框架不起作用, Controller 的 View 始终是全屏 (320*480)。

UIViewController *viewController = [[UIViewController alloc] init];

// view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 130)];
viewController.view = view;
[view release];
AppController *app = (AppController*)[[UIApplication sharedApplication] delegate];

UINavigationController *nav = [app navController];
[nav pushViewController:viewController animated:YES];
[viewController release];

我在 apple developer documents 中搜索 releative thoughts,但我没有发现任何有用的东西。 UIViewController 在显示它之前如何处理它的 View 框架属性?我在哪里可以找到有用的文档。

谢谢。


更新:其实代码来自cocos2d-iphone DirectorTest: https://github.com/cocos2d/cocos2d-iphone/blob/release-2.0-rc1/tests/DirectorTest.m#L143

最佳答案

你完全错了 - 你真的需要阅读(并理解)Apple 的 UIViewController 文档:

View Controller Catalog

View Controller Programming Guide

View Controller Reference

如果您在 View Controller 的代码中创建 View ,您应该在 View Controller 的 loadView 方法中执行此操作。

直接来自 Apple 的文档:

Creating a View Programmatically

If you prefer to create views programmatically ... you do so by overriding your view controller’s loadView method. Your implementation of this method should do the following:

Create a root view object. The root view contains all other views associated with your view controller. You typically define the frame for this view to match the size of the app window, which itself should fill the screen. However, the frame is adjusted based on how your view controller is displayed. See “View Controller View Resizing.”

You can use a generic UIView object, a custom view you define, or any other view that can scale to fill the screen.

Create additional subviews and add them to the root view. For each view, you should do the following:

Create and initialize the view. For system views, you typically use the initWithFrame: method to specify the initial size and position of the view. Add the view to a parent view using the addSubview: method. Assign the root view to the view property of your view controller.

关于ios - iOS 在显示之前如何设置 ViewController View 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10820037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com