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?
這是工作,但我遇到了一個問題。每個選項卡都是導航控制器,我將導航欄設置爲隱藏。某些按鈕用自己的xib推送表視圖,需要導航欄出現,所以當出現這些時,我取消隱藏導航欄。這會導致UIButtons向下滑動導航欄的高度,但不是ImageView。關於如何防止這種情況發生的任何想法? – user717452