iPad方向/框架尺寸问题

iPad方向/框架尺寸问题,ipad,ios4,orientation,Ipad,Ios4,Orientation,在“视图确实加载”中,我试图确定视图的大小,以便可以适当地调整子视图的大小。我希望它总是在屏幕的长度和宽度上伸展,而不管方向如何 quest *anview = [[quest alloc] initWithFrame: CGRectMake(50, 50, self.view.frame.size.width-100, self.view.frame.size.height-100)]; self.aquest=anview; NSLog(@"size w:%f",self.view

在“视图确实加载”中,我试图确定视图的大小,以便可以适当地调整子视图的大小。我希望它总是在屏幕的长度和宽度上伸展,而不管方向如何

quest *anview = [[quest alloc] initWithFrame: CGRectMake(50, 50, self.view.frame.size.width-100, self.view.frame.size.height-100)];
self.aquest=anview;
    NSLog(@"size w:%f",self.view.frame.size.width);
    NSLog(@"size h:%f",self.view.frame.size.height);
但这总是返回748的宽度和1024的高度,当我在风景中时,它应该返回相反的结果。我知道你无法在模拟器上获得方向,但这也发生在设备上。当我获得定向时:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(@"device orientation:%d",orientation);
我正确地获得了方向,但无论方向如何,此日志语句都返回748/1024

quest *anview = [[quest alloc] initWithFrame: CGRectMake(50, 50, self.view.frame.size.width-100, self.view.frame.size.height-100)];
self.aquest=anview;
    NSLog(@"size w:%f",self.view.frame.size.width);
    NSLog(@"size h:%f",self.view.frame.size.height);
有人知道发生了什么吗?这与我将其放入viewdidLoad方法有关吗?我应该把它放在VIEWWILLISPEND还是VIEWDIDDISPEND中

尝试使用bounds属性而不是frame

视图始终在纵向模式下创建,然后旋转,即使在横向模式下启动应用程序也是如此。您应该能够通过将子视图的大小设置为相对于父视图的纵向大小,并将自动调整大小掩码设置为UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingFlexibleHeight,从而使子视图保持拉伸状态,并为正确的设备方向提供shouldAutorotateToInterfaceOrientation:返回YES。除非向遮罩添加不同的UIViewAutoresizingFlexibleMargin,否则它还将保持与上边缘和左边缘的距离