0

我在用:

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

旋转时在某些位置设置按钮和标签。唯一的问题是,当我离开该视图控制器并转到另一个控制器时,使用相同的代码,它不会将按钮和标签移动到定义的 CGRECTMAKE 值。它仅在选定的视图控制器旋转时移动它们。如何让其他视图控制器检测它的方向,并在到达它们时正确调整其大小?

4

2 回答 2

0

每次检测到旋转时,视图控制器都会调用此方法。我假设这就是您目前拥有此代码的地方

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == 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);
    }
}

-=-=-=-=-=-=-=-=-

如果您想在移动到不同的 viewController 时检测方向并相应地放置对象……那么您可以像这样检测您所处的方向:

-(void)viewWillAppear:(BOOL)animated
{
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == 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);
    }
}

-=-=-=-=-=-=-=-=-

供进一步参考:

如何以编程方式确定 iPhone 界面方向?

于 2012-06-12T15:40:00.310 回答
0

将 UIView 的 autoMaskSubView 设置为 false 使用此方法:

 - (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; 
}
于 2012-06-12T15:42:48.420 回答