當(dāng)自定義一個(gè)UIWindow,并在window添加控件搬设,橫屏?xí)r穴店,window并沒有跟隨視圖旋轉(zhuǎn)。
解決方法1:(蘋果推薦這樣使用)
1.定義一個(gè)UIViewController,并設(shè)置為當(dāng)前Window的rootViewController,將控件添加到自定義的UIViewController上拿穴,調(diào)用時(shí)使用self.mineWindow.mineRootViewController.button...
2.在自定義的UIViewController中添加橫屏方法:
- (BOOL)shouldAutorotate {
returnYES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
解決方法2:
對(duì)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)之處請(qǐng)@我泣洞。