2015-01-03 93 views
0

正在尝试更改多个标签和图像宽度取决于设备旋转后的屏幕边界。以下是我已经试过:iOS 7旋转设备未检测到横向屏幕边界

- (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));   
    } 

} 

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

(像:{480320} & {320480})

工作正常在, 但我得到了相同大小的结果测试模拟器和设备。

任何想法,将不胜感激。只有

回答

0

从iOS8上

[UIScreen mainScreen].bounds 

是接口为本(看会议“视图控制器的进步在IOS 8”的WWDC 2014),这意味着在iOS8上的高度和宽度横向模式是相反的。

您可以创建一个helper方法,如下面有相同的行为:

+(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; 
}