[英]Resizing full screen view inside UIViewController on rotation?
我在UIViewController中添加了一個webview。 我假設我可以將它的大小與UIViewController的視圖相匹配,但很快意識到UIControllerView框架與屏幕方向無關,因此顯示框架就像在縱向模式下一樣(所以如果屏幕是在風景中)。 執行UIInterfaceOrientationIsPortrait()
不起作用,因為如果設備平躺,那么即使屏幕旋轉為橫向,它仍會將其報告為縱向。
為了解決這個問題,我檢查了狀態欄的方向,然后使用UIScreen邊界(也獨立於旋轉)來計算當前幀,然后刪除狀態欄的大小(如果它是可見的)。
CGRect frame = [UIScreen mainScreen].bounds;
BOOL isPortrait;
UIDeviceOrientation orientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
isPortrait = YES;
}
else {
isPortrait = NO;
}
if (!isPortrait) {
frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width);
}
if ([UIApplication sharedApplication].statusBarHidden) {
return frame;
}
else {
return CGRectMake(frame.origin.x,
frame.origin.y,
frame.size.width,
frame.size.height - 20);
}
現在我遇到了另一個問題 - 即使我設置我的UIWebView進行自動調整,UIViewController的視圖框架也與旋轉無關,因此它不會改變,因此我的UIWebView在旋轉時不會正確地改變框架。
(奇怪的是,盡管UIViewController視圖框架沒有改變,但視圖實際上確實正確調整了自己的大小)
我已經嘗試使用didRotateFromInterfaceOrientation:
方法,它確實調整了大小,但只在完成所有旋轉動畫之后。
使用willRotateToInterfaceOrientation:duration:
產生與之前相同的問題 - UIInterfaceOrientationIsPortrait()
不是方向的真實反映。
有人設法做到了嗎?
嘗試自動調整webview和viewcontroller的視圖。 或者你也可以采取另一種觀點並刪除viewcontroller的nib文件中的默認視圖。 自動調整該視圖並連接到視圖插座。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.