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));

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容