좋아요, 그래서 이것을 정리했습니다. UIImagePickerController 클래스는 Apple documentation에 따라 세로 모드 만 지원합니다.
회전을 캡처하려면 willRotateToInterfaceOrientation
은 쓸모가 없습니다. 따라서 알림을 사용해야합니다. 런타임에 autolayout contraints를 설정하는 것은 방법이 아닙니다. UIViewController
는 다음을 추가 cameraOverlayView의
// send notification on rotation
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
viewDidLoad
에서 방법 : 당신이 활성화 회전 알림에 필요한 AppDelegate에 didFinishLaunchingWithOptions
에서
//add observer for the rotation notification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
가 마지막으로 cameraOverlay에
orientationChanged:
방법을 추가
UIViewController
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
double rotation = 0;
switch (orientation) {
case UIDeviceOrientationPortrait:
rotation = 0;
break;
case UIDeviceOrientationPortraitUpsideDown:
rotation = M_PI;
break;
case UIDeviceOrientationLandscapeLeft:
rotation = M_PI_2;
break;
case UIDeviceOrientationLandscapeRight:
rotation = -M_PI_2;
break;
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationUnknown:
default:
return;
}
CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.btnCancel.transform = transform;
self.btnSnap.transform = transform;
}completion:nil];
}
위의 코드는이 경우 btnCancel과 btnSnap을 사용하는 2 개의 UIButton에 회전 변환을 적용합니다. 장치 회전시 카메라 응용 프로그램 효과가 나타납니다. 콘솔에서 여전히 경고가 나타납니다 <Error>: CGAffineTransformInvert: singular matrix.
왜 이런 일이 발생하는지 확신 할 수 없지만 카메라보기와 관련이 있습니다.
희망 사항이 도움이됩니다.
같은 질문을 한 번 전 요청했습니다. http://stackoverflow.com/questions/15377120/uiimagepickercontroller-record-video-with-landscape-orientation 불행히도 좋은 답변이 없습니다. –
글쎄, 나는 xcode의 Autolayout Constraints를 둘러 보았지만 원래의 세로 바닥이 아닌 현재 오리엔테이션 바닥에 요소를 고정시키는 것이 분명하다. 다음 번 시도는 런타임시'- (void) willRotateToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation duration : (NSTimeInterval) duration'으로 조건을 설정하려고 시도 할 것입니다. @Aaron을 통해 제안 사항이 있습니까? – pechar