189 8069 5689

ios开发横屏适配,ios开发锁定横屏

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

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

创新互联长期为上1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为百色企业提供专业的成都网站设计、成都做网站,百色网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。

解决方法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 如何设置横竖屏自适应

在xcode的工程中,目前已经能够选择APP是否使用横屏还是竖屏了,但其实APP还是可以进行横竖屏切换。有几个办法

1、代码法:

C++代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

//看下面的,自己可以调整,以达到你想要的效果,比如只能横屏显示,只能竖屏显示,或者直接返回YES,表示可以支持任何方向的旋转.

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

当然这段return中其实有很多判断:

C++代码

return (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight);

//这里是支持哪个方向的转动

return (toInterfaceOrientation == UIInterfaceOrientationPortrait)

|| (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft)

|| (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight)

|| (toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);

2、其实还可以在代码之外操作:

设置应用程序的横竖屏显示很简单,默认新建的工程,是支持左横屏,右横屏,竖屏三种方式的,若不希望横屏显示,只需要在工程的配置文件中删除掉横屏的两个item即可。

记得在:Supported interface orientations 有三个项的,items0,如果你要固定横、竖屏,记得将items0展开看一下,如果不是自己需要,就删除吧。我在设置横屏的时候,就不需要这个items0。于是将它删除了

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,这样就可以避免这个问题了。

ios开发iphone6横屏启动图怎么设置

1、iPhone6 Plus共有两种显示模式,分别为标准和放大模式官网 留言只有在“标准模式”下,才支持横屏。所以要确保显示模式在标准模式状态下。

2、在控制中心将“方向锁定”关闭即可让iPhone Plus在手机横放时自动变成横屏显示。

iPhone6 Plus显示模式更改方法

激活苹果6手机时,会让你选择显示模式,如果要更改就看下面的步骤。

1、点击主屏上的“设置”

2、在设置选项列表中找到“显示与亮度”。

3、点击“显示模式”

4、选择“放大”或者“标准”模式

5、切换不同的显示模式之后需要重启苹果手机才能生效

ios开发中怎么让所有页面都是横屏显示

你只需要修改info.plist 文件就可以了。找到"Supported interface orientations" 设置item 项为Portrait就可以了。这个设置为全局设置。


当前文章:ios开发横屏适配,ios开发锁定横屏
本文链接:http://cdxtjz.cn/article/dsdjpgg.html

其他资讯