繁体   English   中英

iPhone和iPad定位(通用应用)

[英]iPhone & iPad orientation (universal app)

我试图根据设备显示不同的方向。

在iPhone上我想允许纵向,在iPad上我想允许landscapeleft方向。

那可能吗?

我试过了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    else {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}

将此添加到您的应用代理:( Swift)

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue | UIInterfaceOrientationMask.LandscapeRight.rawValue)
    }
}

您发布的代码完成了这项工作。 但是,您需要将支持的设备方向添加到Info.plist。 最简单的方法是在Project->Target->Summary->Supported Device Orientations部分中选择适当的设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM