iPhone 앱을 만들고 있는데 세로 모드로 설정해야하므로 사용자가 기기를 옆으로 움직이면 자동으로 회전하지 않습니다. 어떻게해야합니까?가로 방향을 어떻게 비활성화 할 수 있습니까?
답변
특정보기 컨트롤러에 방향 을 비활성화하려면 supportedInterfaceOrientations
및 preferredInterfaceOrientationForPresentation
을 무시해야합니다.
- (NSUInteger) supportedInterfaceOrientations { // Return a bitmask of supported orientations. If you need more, // use bitwise or (see the commented return). return UIInterfaceOrientationMaskPortrait; // return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; } - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation { // Return the orientation you'd prefer - this is what it launches to. The // user can still rotate. You don't have to implement this method, in which // case it launches in the current orientation return UIInterfaceOrientationPortrait; }
당신이 아이폰 OS 6 세 이상 뭔가를 대상으로하는 경우
, 당신은shouldAutorotateToInterfaceOrientation:
방법을 원한다. '예'를 반환 할 때를 변경하면 해당 방향으로 회전할지 결정합니다. 이렇게하면 일반적인 세로 방향 만 허용됩니다. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
// Use this to allow upside down as well
//return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
주 shouldAutorotateToInterfaceOrientation:
이는 아이폰 OS 6.0에서 더 이상 사용되지 않습니다.
클래스에서 shouldAutorotateToInterfaceOrientation
메소드를 완전히 삭제해도 작동합니다. 회전을 계획하지 않는다면 클래스에 메서드를 포함하는 것은 의미가 없으며 코드가 적을수록 일을 깨끗하게 유지할 수 있습니다. 엑스 코드 4
이 답변은 현재 사용되지 않습니다. 'shouldAutorotateToInterfaceOrientation'은 몇 년 동안 사용되지 않았습니다. –
@MarkAmery https://developer.apple.com/reference/uikit/uiviewcontroller/1621419-shouldautorotate에는 지원 중단 알림이 없습니다. –
@ VaddadiKartick 또한이 답변에서 언급 한 방법과는 다른 방법입니다. 나는 당신의 요점이 무엇인지 확신 할 수 없다. –
를 놓친 사람들을 위해
아래 :
: 앱 (모든 컨트롤러의 메소드를 오버라이드 (override) 할 필요가 없습니다)를 통해 방향을 해결하기 위해 프로젝트 설정 화면을 사용할 수 있습니다지원되는 인터페이스 방향을 전환하는 것만 큼 간단합니다. 왼쪽 패널> 앱 타겟> 요약 탭에서 프로젝트를 클릭하여 찾을 수 있습니다.
이것은 더 이상 사용되지 않습니다. 이제 UI가 다릅니다. –
엑스 코드 5
- 위는 일반 탭으로 프로젝트 설정
- 이동을 열려면 왼쪽 사이드 바에서 프로젝트 네비게이터에서 프로젝트를 클릭합니다. 이 같은 장치 방향에서 당신이 배포 정보 섹션에서 원하지 않는
- 의 선택을 취소 옵션은
광산에서 풍경을 선택 취소 할 수 없습니다. 그것은 즉시 그들을 다시 켭니다. 또한 Info.plist에서 삭제하면 다시 되돌립니다. – Almo
스위프트 3 당신이있는 navigationController가있는 경우, 서브 클래스를 (인물 사진 전용) :
class CustomNavigationViewController: UINavigationController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return UIInterfaceOrientation.portrait
}
}
- 1. iPhone에서 가로 방향을 어떻게 코딩합니까?
- 2. iPhone에서 가로 방향을 어떻게 코딩합니까?
- 3. SketchFlow를 사용하여 WP7 템플릿에서 가로 방향을 어떻게 찾을 수 있습니까?
- 4. element.style을 어떻게 비활성화 할 수 있습니까?
- 5. 어떻게 _moz_resizing을 비활성화 할 수 있습니까?
- 6. 어떻게 스크롤 뷰를 비활성화 할 수 있습니까?
- 7. 어떻게 Microsoft.VisualStudio.TestTools.TestTypes.Unit.TestFailedException을 비활성화 할 수 있습니까?
- 8. 버튼을 어떻게 활성화/비활성화 할 수 있습니까?
- 9. 어떻게 캐스케이드 옵션을 비활성화 할 수 있습니까?
- 10. 트랙볼을 어떻게 비활성화 할 수 있습니까?
- 11. 가로 방향에서 가로 방향으로 요소 방향을 변경하십시오.
- 12. Android에서 가로 방향을 뒤집으시겠습니까?
- 13. 텍스트의 방향을 어떻게 알 수 있습니까?
- 14. 사각형이 이동하는 방향을 어떻게 바꿀 수 있습니까?
- 15. 런타임에 HttpModule을 활성화/비활성화 할 수 있습니까?
- 16. iPhone/iPad 화면의 현재 방향을 어떻게 쿼리 할 수 있습니까?
- 17. SVG에서 텍스트의 방향을 어떻게 바꿀 수 있습니까?
- 18. ToolBarTray 방향을 어떻게 동적으로 조정할 수 있습니까?
- 19. .NET에서 PDF 문서 내의 페이지 방향을 어떻게 얻을 수 있습니까?
- 20. UIView가 인터페이스 방향을 "무시"할 수 있습니까?
- 21. Cocos2d에서만 가로 방향을 회전하는 방법
- 22. PDF 페이지의 페이지 방향을 어떻게 얻을 수 있습니까?
- 23. vs2008에서 자동 서식을 비활성화 할 수 있습니까?
- 24. phpBB 로그인을 무시하거나 비활성화 할 수 있습니까?
- 25. Xcode 4에서 디버거를 비활성화 할 수 있습니까?
- 26. 중간 모델의 출력을 비활성화 할 수 있습니까?
- 27. IE에서 Alt-Enter를 어떻게 비활성화 할 수 있습니까?
- 28. 특정 클래스에 대한 Log4perl 출력을 어떻게 비활성화 할 수 있습니까?
- 29. 데모 용 log4j RollingFileAppender 버퍼링을 어떻게 비활성화 할 수 있습니까?
- 30. 어떻게 ckeditor에서 저장 버튼을 비활성화 할 수 있습니까?
보기 contr oller가 내비게이션 컨트롤러에 있으면, 내비게이션 컨트롤러는 이들이 구현 될 필요가있는 곳이다. –
@ MrRogers 나는 그렇게했지만 효과가 없다. http://pastebin.com/dLfLLP2j를 참조하십시오. 모든 컨트롤러는 supportedInterfaceOrientations를 올바르게 구현합니다. 첫 번째보기 컨트롤러는 iPhone Plus 홈 화면의 장치에서 앱을 실행해도 세로 방향으로 올바르게 표시됩니다. 그러나 다른 컨트롤러를 탐색 할 때 장치를 앞뒤로 돌려 다른 컨트롤러를 가로 방향으로 설정 한 다음 다시 돌아 오면 첫 번째 컨트롤러가 현재 가로 방향입니다. 내가 원하는 것은 첫 번째 컨트롤러가 초상화에 있고 두 번째 컨트롤러가 .all이되는 것입니다. –
'supportedInterfaceOrientations' (첫 번째 코드 줄)에서'NSUinteger'를'UIInterfaceOrientationMask'로 재 배열 할 것을 제안합니다. Xcode 8은 "supportedInterfaceOrientations '의 구현에서 충돌하는 반환 유형에 대해 경고합니다.'UIInterfaceOrientationMask '(일명'enum UIInterfaceOrientationMask ')와'NSUInteger '(일명'unsigned long ')"를 비교하면 sens가됩니다. 답변 주셔서 감사합니다 – GabLeRoux