티스토리 뷰

Mobile/iOS

[iOS/swift] Screen Orientation

out of coding 2017. 12. 31. 11:04

앱을 시작할때의 화면을 고정시키고 싶을때 사용하는 방법에 대해서 알아보도록 합시다.


일단 Deployment Info에서 Orientation을 다 열어주면 회전이 다 되는것을 알수가 있는데요.


하지만 Splash Screen에서 화면 회전을 하지 말아야 하는 경우가 발생하게 되는데요.

이런 경우에는 아래와 같이 하면 됩니다.


1. Deployment Info 설정


Portrait만 냅두고 다른것들은 다 꺼줍니다.



2. AppDelegate 파일의 delegate를 변경


설정된 delegate 외에는 동작하지 않도록 다음과 같이 설정합니다.


1
2
3
4
5
6
7
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if let rootViewController = window?.rootViewController {
        return rootViewController.supportedInterfaceOrientations
    }
        
    return .portrait
}
cs


3. ViewController의 delegate를 변경


하고 싶은 설정으로 변경을 하여 줍니다.

넣어주지 않는다면 기본값은 portrait입니다.


1
2
3
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}
cs


4. 옵션


영어가 약한 저로써도 알수가 있습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public struct UIInterfaceOrientationMask : OptionSet {
 
    public init(rawValue: UInt)
 
    
    public static var portrait: UIInterfaceOrientationMask { get }
 
    public static var landscapeLeft: UIInterfaceOrientationMask { get }
 
    public static var landscapeRight: UIInterfaceOrientationMask { get }
 
    public static var portraitUpsideDown: UIInterfaceOrientationMask { get }
 
    public static var landscape: UIInterfaceOrientationMask { get }
 
    public static var all: UIInterfaceOrientationMask { get }
 
    public static var allButUpsideDown: UIInterfaceOrientationMask { get }
}
cs


옵션은 배열로 합쳐서 넣어줄수 있으니 참고 바랍니다.


1
[.portrait, .landscapeLeft]
cs


올해의 마지막 날도 힘내세요.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함