美文网首页iOS技术交流
iOS 自定义UIWindow 横屏时适配问题

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

作者: weixiaoxinghun | 来源:发表于2017-08-15 18:43 被阅读0次

当自定义一个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 横屏时适配问题

    本文链接:https://www.haomeiwen.com/subject/lxmvrxtx.html