1

我从主视图的大小制作了一个日志,我在orientation=4日志上遇到了奇怪的大小。我无法弄清楚问题是什么。这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}

- (void)orientationDidChange:(NSNotification *)note
{
    int orientation = [[UIDevice currentDevice] orientation];
    NSLog(@"orientation=%i -------------------------------",orientation);
    CGRect f = self.view.frame;                     NSLog(@"self.view.frame =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
    f = self.view.bounds;                           NSLog(@"self.view.bounds=(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
    f = [[UIScreen mainScreen] applicationFrame];   NSLog(@"main.app.frame  =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
    f = [[UIScreen mainScreen] bounds];             NSLog(@"main.bounds     =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);

}

结果如下:

orientation=1 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000)
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000)
main.app.frame  =(0.000000, 20.000000, 320.000000, 460.000000)
main.bounds     =(0.000000, 0.000000, 320.000000, 480.000000)

orientation=0 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000)
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000)
main.app.frame  =(0.000000, 20.000000, 320.000000, 460.000000)
main.bounds     =(0.000000, 0.000000, 320.000000, 480.000000)

orientation=4 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000) <== First time size
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000) <== First time size
main.app.frame  =(0.000000, 20.000000, 320.000000, 460.000000) <== First time size
main.bounds     =(0.000000, 0.000000, 320.000000, 480.000000) <== First time size

orientation=2 -------------------------------
self.view.frame =(20.000000, 0.000000, 300.000000, 480.000000)
self.view.bounds=(0.000000, 0.000000, 480.000000, 300.000000)
main.app.frame  =(20.000000, 0.000000, 300.000000, 480.000000)
main.bounds     =(0.000000, 0.000000, 320.000000, 480.000000)

orientation=4 -------------------------------
self.view.frame =(20.000000, 0.000000, 300.000000, 480.000000) <== Why is it different?
self.view.bounds=(0.000000, 0.000000, 480.000000, 300.000000) <== Why is it different?
main.app.frame  =(20.000000, 0.000000, 300.000000, 480.000000) <== Why is it different?
main.bounds     =(0.000000, 0.000000, 320.000000, 480.000000) <== Why is it different?

我为解决此问题而采取的步骤如下:

- cmd+right arrow
- cmd+right arrow
- cmd+left arrow
4

1 回答 1

0

您不支持方向 UIInterfaceOrientationMaskPortraitUpsideDown(即方向 4)。

因此,当设备为 UIInterfaceOrientationMaskPortraitUpsideDown 时,视图不应旋转。

请注意,当您旋转到方向 4 时,这些值与前一个方向的尺寸完全相同。

要解决这个问题:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortraitUpsideDown;
}

并确保您也为支持设备方向选择了倒置。

于 2013-11-03T03:30:46.493 回答