ipad和iphone横竖屏设置

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


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

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

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

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

也可以转换为source code编辑,

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>


2、重载ViewController的shouldAutorotateToInterfaceOrientation方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return ((interfaceOrientation ==UIDeviceOrientationPortrait)||(interfaceOrientation ==UIDeviceOrientationPortraitUpsideDown));
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值