iOS 自定义UIWindow 横屏时适配问题

当自定义一个UIWindow,并在window添加控件,横屏时,window并没有跟随视图旋转。

解决方法1:(苹果推荐这样使用)

1.定义一个UIViewController,并设置为当前Window的rootViewController,将控件添加到自定义的UIViewController上,调用时使用self.mineWindow.mineRootViewController.button...

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

returnYES;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationLandscapeRight;

}

解决方法2:

对UIWindow进行旋转(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];

}

如有不当之处请@我。

你可能感兴趣的:(iOS 自定义UIWindow 横屏时适配问题)