2012-06-12 74 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?