小编Pet*_*nke的帖子

加载SLComposeViewController时,即使我已将Main UIViewController修复为Portrait,它也会旋转到设备方向

我正在开发iOS8.1中的通用应用程序.

我希望该应用程序始终以纵向方向显示.

我通过添加以下代码强制它.这很有效.

在AppDelegate中:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        // Override point for customization after application launch.

        let value = UIInterfaceOrientation.Portrait.rawValue
        UIDevice.currentDevice().setValue(value, forKey: "orientation")

        return true
    }
Run Code Online (Sandbox Code Playgroud)

我为所有View控件使用以下子类:

class PortraitViewController: UIViewController {

    override func shouldAutorotate() -> Bool {
        return true
    }

    override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
        return UIInterfaceOrientation.Portrait
    }

    override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,我在我的应用程序中添加了一个SLComposeViewController,以便用户可以发布到Facebook.如果用户在设备处于横向状态时打开此SLComposeViewController,则SLComposeViewController将接管并旋转屏幕,包括已呈现的所有其他ViewController.

我想强制SLComposeViewController始终保持纵向方向,但无法弄清楚如何让它工作.

谁能帮我?

这是我用来打开SLComposeViewController的代码.

func pressFacebook(){
    if PortraitSLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
        var facebookSheet: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook) …
Run Code Online (Sandbox Code Playgroud)

iphone ios slcomposeviewcontroller swift

4
推荐指数
1
解决办法
725
查看次数

标签 统计

ios ×1

iphone ×1

slcomposeviewcontroller ×1

swift ×1