"interfaceOrientation"은 iOS 8에서 더 이상 사용되지 않습니다.이 메서드를 변경하는 방법 Objective C
이 방법을 사용하는 Cocoa Controls에서 simpleCamera 뷰를 다운로드했습니다.
- (AVCaptureVideoOrientation)orientationForConnection
{
AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait;
switch (self.interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
case UIInterfaceOrientationPortraitUpsideDown:
videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
default:
videoOrientation = AVCaptureVideoOrientationPortrait;
break;
}
return videoOrientation;
}
문제는 iOS 8에서 더 이상 사용되지 않는 "interfaceOrientation"이지만 스위치 조건에서 이것을 대체하는 방법과 방법을 모릅니다.
장치 방향 확인이 올바르지 않습니다. 예를 들어 기기가 가로 모드 일 수 있지만 세로 만 지원하는 뷰 컨트롤러는 세로 모드로 유지됩니다.
대신 다음을 사용하십시오.
[[UIApplication sharedApplication] statusBarOrientation]
또 다른 보너스는 여전히 UIInterfaceOrientation 열거 형을 사용하므로 코드를 거의 변경할 필요가 없다는 것입니다.
iOS8부터 Apple은 interfaceOrientation 대신 TraitCollections (크기 클래스)를 사용할 것을 권장합니다.
또한 iOS 9와 새로운 iPad는 "멀티 태스킹"기능을 갖추고 있기 때문에 장치 방향이 창 비율에 맞지 않는 경우가 있습니다! (애플리케이션 UI 중단)
따라서 전체 iPad 화면을 차지할 필요가 없기 때문에 Regular Size Classes를 사용할 때도 매우주의해야합니다.
때로는 TraitCollections가 모든 디자인 요구 사항을 채우지 못합니다. 이러한 경우 Apple은 뷰의 경계를 비교할 것을 권장합니다.
if view.bounds.size.width > view.bounds.size.height {
// ...
}
상당히 놀랐지 만 iOS 9의 iPad에서 멀티 태스킹 시작하기 WWDC 2015 동영상 ( 21 분 15 초)에서 확인할 수 있습니다.
화면이나 창 비율이 아니라 실제로 장치 방향을 찾고있을 수 있습니다. 장치 카메라에 관심이 있다면 TraitCollection을 사용하지 말고 뷰 경계도 사용하지 마십시오.
-orientation
UIDevice의 속성을 사용하는 것은 정확하지 않으며 (대부분의 경우 작동 할 수 있더라도) 일부 버그로 이어질 수 있습니다. 예를 들어 UIDeviceOrientation
장치가 위 또는 아래로 향하는 경우 장치의 방향도 고려하십시오. UIInterfaceOrientation
열거 형 에는 쌍이 없습니다. 가치.
또한 앱을 특정 방향으로 잠그면 UIDevice는이를 고려하지 않고 장치 방향을 제공합니다.
반면에 iOS8은 클래스 의 interfaceOrientation
속성을 더 이상 사용하지 않습니다 UIViewController
.
인터페이스 방향을 감지하는 데 사용할 수있는 두 가지 옵션이 있습니다.
- 상태 표시 줄 방향 사용
- iPhone에서 크기 클래스를 사용하면 재정의되지 않은 경우 현재 인터페이스 방향을 이해할 수 있습니다.
아직 누락 된 것은 인터페이스 방향 변경 방향을 이해하는 방법입니다. 이는 애니메이션 중에 매우 중요합니다.
WWDC 2014 "iOS8의 컨트롤러 발전보기"세션에서 스피커는 .NET Framework를 대체하는 방법을 사용하여 해당 문제에 대한 솔루션도 제공합니다 -will/DidRotateToInterfaceOrientation
.
여기에 제안 된 솔루션이 부분적으로 구현되었습니다.
-(void) viewWillTransitionToSize:(CGSize)s withTransitionCoordinator:(UIVCTC)t {
orientation = [self orientationFromTransform: [t targetTransform]];
oldOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self myWillRotateToInterfaceOrientation:orientation duration: duration];
[t animateAlongsideTransition:^(id <UIVCTCContext>) {
[self myWillAnimateRotationToInterfaceOrientation:orientation
duration:duration];
}
completion: ^(id <UIVCTCContext>) {
[self myDidAnimateFromInterfaceOrientation:oldOrientation];
}];
}
Swift 4+ 버전
UIApplication.shared.statusBarOrientation
'program tip' 카테고리의 다른 글
$ location을 사용하여 AngularJS의 새 페이지로 리디렉션 (0) | 2020.10.26 |
---|---|
.css 파일 (flask / python)을 선택하지 않는 애플리케이션 (0) | 2020.10.26 |
사용하지 않는 포함은 C / C ++에서 유해합니까? (0) | 2020.10.26 |
오류 415 지원되지 않는 미디어 유형 : JSON 인 경우 POST가 REST에 도달하지 않지만 XML 인 경우에는 도달합니다. (0) | 2020.10.26 |
Python Flask 앱을 여러 파일로 분할 (0) | 2020.10.26 |