【问题标题】:why is the landscape mode view still show width less then height?为什么横向模式视图仍然显示宽度小于高度?
【发布时间】:2010-07-27 00:17:29
【问题描述】:

试试这个,

假设你有一个简单的横向模式 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 的东西。

相反,我总是得到 width:320.000,height:480.000 实际方向是什么。

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

【问题讨论】:

    标签: iphone landscape


    【解决方案1】:

    尝试获取宽度/高度:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
    
    {
      NSLog(@"view frame: %@",NSStringFromCGRect(self.view.frame));
    }
    

    您的视图还需要设置 UIAutoresizingMasks 才能在旋转时调整大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多