iPhone转动时表现不尽如人意

时间:2012-08-06 22:00:45

标签: iphone xcode user-interface rotation

我的应用在每个视图上有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; 
}

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

1 个答案:

答案 0 :(得分:1)

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

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

另一个是在任何旋转发生之前调用此方法,因此您的帧会被更改,然后设备会被旋转,任何默认的自动调整都意味着帧不是您期望的