
正文
ios横屏开发,iOS 强制横屏
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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];
}
如有不当之处请@我。
相关问答
Q1: ios开发中怎么让所有页面都是横屏显示
你只需要修改info.plist 文件就可以了。找到"Supported interface orientations" 设置item 项为Portrait就可以了。这个设置为全局设置。
Q2: iOS屏幕自动旋转问题 以及横屏模式打开APP出现的问题
preferredInterfaceOrientationForPresentation 打开时当前界面的朝向
shouldAutorotate 是否支持旋转
supportedInterfaceOrientations 所支持的旋转方向
return返回的为当前选中 tabar 的支援情况
在 tabbar 中放UINavigationController后 还需要在 UINavigationController父类中实现如下
然后如果某个界面想支持屏幕旋转 只需要在Controller里面重写写方法即可
需要在 如下方法中新加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];//此方法
....
}
这样就会解决横屏模式下打开 APP 产生的一些问题
(情况二 容易出现的一些问题为:当你在didFinishLaunchingWithOptions中 加载了另一个 window 的时候需要在自己建的 window 中也遵守屏幕旋转的几个代理方法 不然横屏模式下打开APP布局依然会乱)
有问题请留言 TUT (编辑于 2018.09.03)
Q3: iOS开发 横竖屏切换问题
在你想支持横竖屏的viewController里面重写两个方法:
1
2
3
4
5
6
7
8
9
10
11
// 支持设备自动旋转
- (BOOL)shouldAutorotate
{
return YES;
}
// 支持横竖屏显示
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
这样在这个viewController中就可以横竖屏切换了。
注意如果你window的rootViewController是一个navigationController,可能会出现以下问题:
你的navigationController只支持竖屏,但是你push到了某个新的controller中,这个controller支持横竖屏,当你在新的controller中切换到横屏后(也有可能在切换到横屏然后pop回来后),这时候程序会闪退,因为你的navigationController不支持横屏。
如果你想解决这个问题,就需要自己写一个UINavigationController的子类,在这个类中重写方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (BOOL)shouldAutorotate
{
return [self.viewControllers.lastObject shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
然后用这个类去创建实例作为window的rootViewController,这样就可以避免这个问题了。
Q4: ios开发iphone6横屏启动图怎么设置
1、iPhone6 Plus共有两种显示模式,分别为标准和放大模式官网 留言只有在“标准模式”下,才支持横屏。所以要确保显示模式在标准模式状态下。
2、在控制中心将“方向锁定”关闭即可让iPhone Plus在手机横放时自动变成横屏显示。
iPhone6 Plus显示模式更改方法
激活苹果6手机时,会让你选择显示模式,如果要更改就看下面的步骤。
1、点击主屏上的“设置”
2、在设置选项列表中找到“显示与亮度”。
3、点击“显示模式”
4、选择“放大”或者“标准”模式
5、切换不同的显示模式之后需要重启苹果手机才能生效
Q5: ios15.2桌面怎么开横屏?
下拉控制中心就能打开,如果不行,可能系统bug了,手机重启一下试一试。






