티스토리 뷰
AppDelegate 에서
class AppDelegate: UIResponder, UIApplicationDelegate {
.....
var shouldSupportAllOrientation = true
//화면회전을 잠그고 고정할 목적의 플래그 변수를 추가한다.
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if (shouldSupportAllOrientation == true){
return UIInterfaceOrientationMask.all
// 모든방향 회전 가능
}
return UIInterfaceOrientationMask.portrait
// 세로방향으로 고정.
}
.....
}
위와 같이 설정 후
화면을 고정하고자 하는 view controller 에서
let appDelegate = UIApplication.shared.delegate as! AppDelegate
override func viewWillAppear(_ animated: Bool) {
appDelegate.shouldSupportAllOrientation = false
}
override func viewWillDisappear(_ animated: Bool) {
appDelegate.shouldSupportAllOrientation = true
}
해주면 된다.
* viewWillDisappear 에서 true로 해주는 것을 깜빡할경우
이후 모든 뷰컨트롤러에서 화면이 고정되므로 각별히 주의해야함.
참고.
UIInterfaceOrientationMask 의 설정값은 아래와 같다.
의도에 맞게 설정하면 됨.
.all (모든방향)
.allButUpsideDown (세로뒤집기 빼고 모든방향)
.landscape (가로)
.landscapeLeft (가로 왼쪽만)
.landscapeRight (가로 오른쪽만)
.portrait (세로. 뒤집기 불가)
.portraitUpsideDown (뒤집기 포함한 세로)
'Swift' 카테고리의 다른 글
Application Loader 간단 사용법 (0) | 2017.06.02 |
---|---|
[에러]This action could not be completed. Try Again (-22421) (0) | 2017.06.01 |
어떤 값을 넣어야 될지 모르겠을 때. (0) | 2017.04.24 |
화면이 Landscape 상태인지 확인하는 방법. (0) | 2017.04.20 |
현재 디바이스가 pad인지 확인하는 방법. (0) | 2017.04.20 |
- Total
- Today
- Yesterday
- 아이폰
- Application Loader
- 업로드
- 열거형
- 화면회전
- ios
- 애플와치
- homepod
- xcode
- 아이패드
- IPA
- Apple TV
- 단말기 확인
- 아이맥 프로
- Swift
- 개발
- 애플
- TVos
- 장치 확인
- 워치os
- 스위프트
- 열거
- watchOS
- 홈팟
- Watch OS
- 22421
- AppleTV
- iOS7
- 어플리케이션 로더
- 애플리케이션 로더
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |