2012-06-12 104 views
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值。它只会在选定的视图控制器旋转时移动它们。我怎样才能让其他视图控制器检测它的方向,并在找到它时正确调整大小?

回答

0

设置的UIView的autoMaskSubView假 使用这种方法:

- (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; 
} 
+0

这是工作,但我遇到了一个问题。每个选项卡都是导航控制器,我将导航栏设置为隐藏。某些按钮用自己的xib推送表视图,需要导航栏出现,所以当出现这些时,我取消隐藏导航栏。这会导致UIButtons向下滑动导航栏的高度,但不是ImageView。关于如何防止这种情况发生的任何想法? – user717452

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?