-2

I'm developing an iOS app using Swift and my app should be in portrait mode. I have one on view to capture images. I want to display that view only in landscape mode. This app is for iOS 7 or above.

In the project "General" Device Orientation is set as "Portrait"

In the storyboard Simulated Metrics section the orientation is set as "Landscape"

Above image shows the UIViewController settings in the storyboard and following code is in the UIViewConroller.

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

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

This doesn't give the expected output.

I'm new to iOS development I have no idea how to achieve this.

Any ideas please.

Oshadha
  • 546
  • 10
  • 25
  • possible duplicate of [Force UIViewController to only show in landscape mode](http://stackoverflow.com/questions/5339662/force-uiviewcontroller-to-only-show-in-landscape-mode) – Kamaros Apr 16 '15 at 22:48
  • @Kamaros Unless you know of a way that this can be done purely through interface builder without writing any code, this can't really be a duplicate of an Objective-C question. – nhgrif Apr 16 '15 at 22:50
  • 2
    @nhgrif Swift and ObjC can use the same frameworks, unless it's a language-specific question, it can totally be a duplicate of an ObjC question. – EmilioPelaez Apr 16 '15 at 23:00
  • @EmilioPelaez The discussions on the meta don't tend to agree with your statement. VB and C# questions aren't being closed as duplicates of each other. – nhgrif Apr 16 '15 at 23:02

2 Answers2

-3

In the project settings you can restrict all views to conform to a single display mode. If you want to restrict just one view, you must do it in code.

Look up "willTransitionToTraitCollection".

Kelvin Lau
  • 6,373
  • 6
  • 34
  • 57
-3

Click On the project->Click on Target->General->Device Orientaion.Uncheck whichever you don't want.enter image description here

gkarya42
  • 429
  • 6
  • 22