iPad和iPhone横竖屏设置

最近做了个支持iphone和ipad的小应用,被横竖屏切换搞得有点难受,这里做一下总结。

1、在info.plist文件中做横竖屏的设置

一般在info.plist文件中有这两个属性(Supported interface orientations)、(Supported interface orientations (iPad))

这两个属性是设置横竖屏相关的,对应的是一个数组

如果不想横屏,只设置一个item,设置为(Portrait (bottom home button))就好了,如果需要横屏,可以选择其他选项

也可以转换为source code编辑,

UISupportedInterfaceOrientations

UIInterfaceOrientationPortrait

UISupportedInterfaceOrientations~ipad

UIInterfaceOrientationPortrait

UIInterfaceOrientationPortraitUpsideDown

2、重载ViewController的shouldAutorotateToInterfaceOrientation方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

// Return YES for supported orientations

return ((interfaceOrientation ==UIDeviceOrientationPortrait)||(interfaceOrientation ==UIDeviceOrientationPortraitUpsideDown));

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、UIDeviceOrientation 设备的物理方向 简介UIDeviceOrientation即我们手持的...
    MrJ的杂货铺阅读 28,147评论 8 75
  • 见www.jianshu.com/p/59279b018217 Application can be killed...
    heatbeats阅读 3,160评论 0 0
  • iPhone 最暴力的方法: 首先要强制应用只能响应竖屏,在AppDelegate中添加以下方法。返回的枚...
    时尚灬IT男阅读 696评论 0 0
  • 稻花香里说丰年,露珠点点连一片。如果你不曾早起,沉浸在大自然,那么你永远无法领略大自然早晨的奇妙和美好。早晨,一切...
    花缘过客阅读 606评论 2 1
  • 文/小叶 你因梦想而在这个世上受苦, 就像一条河流,因云和树的倒影, 不是云和树而受苦。 ——切斯拉夫.米沃什 “...
    博土阅读 445评论 1 2

友情链接更多精彩内容