1

我的应用程序在每个视图上有 3 个按钮和 1 个图像视图。由于按钮和图像的大小以及导航栏和标签栏控制器的大小,需要调整大小以使横向模式下的所有内容都变小。我将以下代码放入:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    viewofimage.frame = CGRectMake(130, 45, 220, 115);
    share.frame = CGRectMake(205, 161, 70, 70);
    invite.frame = CGRectMake(8, 161, 70, 70);
    contact.frame = CGRectMake(402, 161, 70, 70);
    invitation.frame = CGRectMake(3, 227, 81, 21);
    sharing.frame = CGRectMake(200, 227, 81, 21);
    contacting.frame = CGRectMake(397, 227, 81, 21);
}
else
{
    viewofimage.frame = CGRectMake(20, 64, 280, 206);
    invite.frame = CGRectMake(8, 285, 70, 70);
    share.frame = CGRectMake(125, 285, 70, 70);
    contact.frame = CGRectMake(242, 285, 70, 70);
    invitation.frame = CGRectMake(3, 358, 81, 21);
    sharing.frame = CGRectMake(120, 358, 81, 21);
    contacting.frame = CGRectMake(237, 358, 81, 21);
}

return YES; 
}

在模拟器中,这表现得很完美,图像视图被调整大小并且一切都是可见的。在设备上,它只是将所有内容向右移动。关于错误在代码中的任何想法?

4

1 回答 1

1

不要像这样对值进行硬编码,您应该使用自动调整大小的掩码来处理旋转等事件的大小调整

一个问题可能是 shouldAutoRotate 被缓存并且每次设备旋转时都不会调用,也许可以尝试将此代码移动到 will/did rotate 方法

另一个是在发生任何旋转之前会调用此方法,因此您的框架会发生变化,然后设备会旋转,并且任何默认的自动调整大小都意味着框架不是您所期望的

于 2012-08-06T22:02:02.667 回答