我正在使用:
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值。它只在旋转选定的视图控制器时移动它们。如何让其他视图控制器检测它的方向,并在到达它们时正确调整大小?
答案 0 :(得分:0)
View Controller每次检测到旋转时都会调用此方法。我假设你现在有这个代码的地方
-(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);
}
}
- = - = - = - = - = - = - = - = -
供进一步参考:
How to programmatically determine iPhone interface orientation?
答案 1 :(得分: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;
}