iPad方向/框架尺寸问题

Mar*_*tin 2 orientation ipad ios4

在"View Did Load"中,我正在尝试确定视图的大小,以便我可以适当地调整子视图的大小.我希望它总是伸展屏幕的长度和宽度,无论方向如何.

quest *anview = [[quest alloc] initWithFrame: CGRectMake(50, 50, self.view.frame.size.width-100, self.view.frame.size.height-100)];
self.aquest=anview;
Run Code Online (Sandbox Code Playgroud)

但是当我在风景中它应该返回相反时,它总是返回宽度748和高度1024.我知道你无法在模拟器上获得方向,但这也发生在设备上.当我得到方向时:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(@"device orientation:%d",orientation);
Run Code Online (Sandbox Code Playgroud)

我正确地得到了方向,但是这个日志语句返回748/1024而不管方向如何.

    NSLog(@"size w:%f",self.view.frame.size.width);
    NSLog(@"size h:%f",self.view.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

有谁知道发生了什么?这与我将它放在viewdidLoad方法中有什么关系吗?我应该把它放在viewWillAppear还是viewDidAppear?

sig*_*egv 12

尝试使用bounds属性而不是frame.

即使以横向方式启动应用程序,也始终以纵向模式创建视图,然后旋转视图.您应该能够通过将其大小相对于父级的纵向大小和自动调整掩码设置为UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingFlexibleHeight来保持子视图的延伸,提供了shouldAutorotateToInterfaceOrientation :为正确的设备方向返回YES.它还将保持距离上边距和左边距的距离,除非您向蒙版添加不同的UIViewAutoresizingFlexibleMargin.