我正在创建一个不使用nib文件的iOS应用程序,并希望在应用程序委托中初始化窗口,如下所示:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.backgroundColor = [UIColor greenColor];
NSLog(@"%@", self.window.bounds);
窗口弹出,我可以看到我定义的绿色。当我调试self.window时,我可以看到刚刚定义的框架的边界,但是当我想要访问bounds属性时,它返回null。frame也是一样。有什么区别?
当我想初始化视图时,它不起作用,因为未定义框架/边界以初始化该视图:
// create root view
RootView* rootView = [[[RootView alloc] initWithFrame:self.window.bounds] autorelease];
我做错了什么吗?
NSStringFromCGRect
:) 详见文档:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/doc/uid/TP40006894-CH3-SW19 - deanWombourne