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

}

你可能感兴趣的:(iPad和iPhone横竖屏设置)