1

尝试这个,

假设您有一个简单的横向模式 iphone 应用程序,例如一个简单的视图控制器应用程序。

也像这样取消注释 viewcontroller .m 文件中的自动旋转

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  NSLOG(@"width:%f,height:%f",self.view.frame.size.width,self.view.frame.size.height);
  return YES;
}

之后,只需在 iphone 模拟器上运行这个东西,然后尝试通过 command+left 或 command+right 旋转它。

我希望在纵向和横向模式下会得到类似 width:320.000,height:480.000 和 width:480.000,height:320.000 的东西。

相反,我总是得到宽度:320.000,高度:480.000 实际方向是什么。

所以我的问题是我应该如何自动正确获取视图的大小?

4

1 回答 1

0

尝试获取宽度/高度:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

{
  NSLog(@"view frame: %@",NSStringFromCGRect(self.view.frame));
}

此外,您的视图需要设置 UIAutoresizingMasks 以便在旋转时调整大小。

于 2010-07-26T16:17:29.347 回答