I'm trying to force the orientation for one view in my ipad app but I can't keep it persistent.
For example, I'm in portrait in my collection view, I select an image (which is landscape). I check it's width and it's height in the viewWillAppear of my viewPhoto in order to set the device to landscape. The "device" rotate, well. When I rotate it manually after to portrait, I want it to stay in landscape, but it doesn't.
Here's my code :
override func viewWillAppear(animated: Bool) {
// Remove hairline on toolbar
mytoolBar.clipsToBounds = true
// Load image from svg
let img = getImageFromBase64(arrayBase64Images[index])
imgView.image = img
var value: Int
if ( img.size.width > img.size.height ) { // turn device to landscape
value = UIInterfaceOrientation.LandscapeRight.rawValue
}
else { // turn device to portrait
value = UIInterfaceOrientation.Portrait.rawValue
}
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}