iOS 自定義UIWindow 橫屏?xí)r適配問題

當(dāng)自定義一個UIWindow,并在window添加控件,橫屏?xí)r,window并沒有跟隨視圖旋轉(zhuǎn)。

解決方法1:(蘋果推薦這樣使用)

1.定義一個UIViewController,并設(shè)置為當(dāng)前Window的rootViewController,將控件添加到自定義的UIViewController上,調(diào)用時使用self.mineWindow.mineRootViewController.button...

2.在自定義的UIViewController中添加橫屏方法:
- (BOOL)shouldAutorotate {

returnYES;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationLandscapeRight;

}

解決方法2:

對UIWindow進(jìn)行旋轉(zhuǎn)(UIWindow繼承自UIView):
UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];

if (orientation == UIInterfaceOrientationLandscapeLeft) {

CGAffineTransform rotation = CGAffineTransformMakeRotation(3*M_PI/2);

[self setTransform:rotation];

}

if (orientation == UIInterfaceOrientationLandscapeRight) {

CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI/2);

[self setTransform:rotation];

}

如有不當(dāng)之處請@我。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容