我有一個UIViewController在其中一個UIWebView。我希望UIWebView以橫向和縱向模式位於iPad屏幕的中心。所以,我已經這樣實施了爲什麼我的視圖無法在interfaceOrientation更改上正確定位?
// UIViewController
// InfoGraphicView is the UIWebView
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self layoutPortrait];
} else {
[self layoutLandscape];
}
}
- (void)layoutLandscape {
NSLog(@"Layout Landscape");
infoGraphicView.frame = CGRectMake(100, 100, 936, 700);
}
- (void)layoutPortrait {
NSLog(@"Layout Portrait");
infoGraphicView.frame = CGRectMake(100, 100, 700, 936);
}
但是,它沒有按照我的預期行事。在上面的代碼中,我希望他的UIWebView是100px(或點或任何單位)遠離頂部和左側。但事實並非如此。在肖像模式下,它會與屏幕左上角齊平,而在橫向模式下,它似乎在左上角部分偏離屏幕。
如果我將該幀設置爲CGRectMake(-100, 100, 700, 936)
,那麼我將它定位在屏幕的中心,因爲我希望它是,但我不知道爲什麼。
像往常一樣,最有可能的東西很簡單,我忽略了,但我無法弄清楚。任何幫助一如既往非常感謝。