【问题标题】:iOS 7 rotated device not detecting landscape screen boundsiOS 7 旋转设备未检测到横向屏幕边界
【发布时间】:2015-01-03 16:44:05
【问题描述】:

尝试根据设备旋转后的屏幕边界更改多个标签和图像宽度。这是我尝试过的:

- (void)viewDidLayoutSubviews{
    if( UIInterfaceOrientationIsLandscape( [[UIDevice currentDevice] orientation] )) {

       CGSize newSize;

       newSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);

       NSLog(@"%@",NSStringFromCGSize(newSize));       

    }else if (UIInterfaceOrientationIsPortrait( [[UIDevice currentDevice] orientation] )){

       CGSize newSize;

       newSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);

       NSLog(@"%@",NSStringFromCGSize(newSize));        
    }

}

当我改变方向时它应该记录不同的宽度和高度

(就像在 上一样:{480,320} 和 {320,480})

上工作正常, 但我在 模拟器和 设备上进行了相同大小的测试。

任何想法都将不胜感激。

【问题讨论】:

    标签: iphone5 ios8 ios7 ios7 ios ios7 ios8 screen-orientation detect


    【解决方案1】:

    仅来自 iOS8

    [UIScreen mainScreen].bounds
    

    是面向界面的(查看 WWDC 2014 的会话“iOS 8 中的视图控制器改进”),这意味着在 iOS8 的横向模式下,高度和宽度是相反的。

    您可以创建如下所示的辅助方法以具有相同的行为:

    +(CGRect)getScreenBounds
    {
        CGRect bounds = [UIScreen mainScreen].bounds;
        if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
            bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
        }
        return bounds;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多