1

今天在玩iOS6,我一直在检查各种方向下的视图框架大小,我以为我在iOS5中理解了这一点。(我知道自动布局在很多情况下解决了基本问题,但我仍然觉得我可能出于各种原因需要这个检查?)。

关闭自动布局后,检​​查视图尺寸会返回正确的尺寸大小,但不是正确的边缘。也就是说,在 iPhone 上的纵向 .width 属性 = 320 和横向 .width 属性 = 300,而我希望 300 是高度尺寸的值。

这对我来说有点奇怪,因为 self.view 确实可以正确缩放到窗口,但是设置为 self.view 框架的另一个视图却没有。这很容易通过检查方向然后得到正确的数字来解决,我猜,但我是否遗漏了一些明显的东西,或者 iOS6 中的一些新规则?

//always gives aprox 300 for width despite device orientation
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    screenRect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    screenRect = self.view.window.frame;
    NSLog(@"screen rect size = %f x %f", screenRect.size.width, screenRect.size.height);
    [imageView setFrame:screenRect];
}

//a button to check orientation. always gives aprox 300 for width despite device orientation
- (IBAction)checkScreenSize:(id)sender {
    screenRect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    NSLog(@"screen rect size = %f x %f", screenRect.size.width, screenRect.size.height);
    screenRect = [[UIScreen mainScreen]applicationFrame];
    NSLog(@"screen rect size = %f x %f", screenRect.size.width, screenRect.size.height);
    }
4

0 回答 0