I'm developing a Universal app in iOS8.1.
I would like the app to always appear in Portrait Orientation.
I have forced it by adding the following code. This is working.
In 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
}
I use the following subclass for all my View Controllers:
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)
}
}
Then however, I added an SLComposeViewController to my app so users can post to Facebook. If the user opens this SLComposeViewController while their device is in landscape, the SLComposeViewController takes over and rotates the screen, including all other ViewControllers that are already presented.
I would like to force the SLComposeViewController to always stay in Portrait Orientation, but can't figure out how to get it to work.
Can anyone help me?
This is the code I use to open the 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"))
}
}
Thanks in advance!
I was able to solve this by subclassing SLComposeViewController
import Social
import UIKit
class ComposeViewController: SLComposeViewController {
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With