【发布时间】:2015-03-12 00:31:18
【问题描述】:
我正在 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
}
我的所有视图控制器都使用以下子类:
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)
}
}
然后,我在我的应用程序中添加了一个 SLComposeViewController,以便用户可以发布到 Facebook。如果用户在他们的设备处于横向状态时打开此 SLComposeViewController,则 SLComposeViewController 会接管并旋转屏幕,包括已呈现的所有其他 ViewController。
我想强制 SLComposeViewController 始终保持纵向,但不知道如何让它工作。
谁能帮帮我?
这是我用来打开 SLComposeViewController 的代码。
func pressFacebook(){
if PortraitSLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
var facebookSheet: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookSheet.setInitialText("My Status!")
self.presentViewController(facebookSheet, animated: true, completion: nil)
facebookSheet.addURL(NSURL(string: "www.blahblah.com"))
facebookSheet.addImage(UIImage(named: "fb.jpg"))
}
}
提前致谢!
【问题讨论】:
标签: ios iphone swift slcomposeviewcontroller