pec*_*har 7 landscape portrait uiimagepickercontroller ios
嗨我正在尝试复制相同的旋转,当方向转移到横向时,可以在相机应用程序中看到.不幸的是我没有运气.我需要使用UIImagePickerController为自定义cameraOverlayView设置它.
从这幅肖像(B是UIButtons)
|-----------|
| |
| |
| |
| |
| |
| |
| B B B |
|-----------|
Run Code Online (Sandbox Code Playgroud)
为了这个景观
|----------------|
| B |
| |
| B |
| |
| B |
|----------------|
Run Code Online (Sandbox Code Playgroud)
换句话说,我希望按钮能够粘在原始肖像底部并在其中心旋转.我正在使用Storyboard并启用了Autolayout.任何帮助是极大的赞赏.
pec*_*har 16
好的,所以我设法解决了这个问题.需要注意的是UIImagePickerController类仅支持纵向模式,如Apple 文档所示.
要捕获旋转,willRotateToInterfaceOrientation这里没用,所以你必须使用通知.在运行时设置autolayout约束也不是可行的方法.
在AppDelegate中,didFinishLaunchingWithOptions您需要启用旋转通知:
// send notification on rotation
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)
在viewDidLoadcameraOverlayView的方法中UIViewController添加以下内容:
//add observer for the rotation notification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
最后将orientationChanged:方法添加到cameraOverlayUIViewController
- (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];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在我使用的2个UIButtons上应用了旋转变换,在这种情况下是btnCancel和btnSnap.这样可以在旋转设备时为您提供相机应用效果.我仍然在控制台中收到警告,<Error>: CGAffineTransformInvert: singular matrix.不知道为什么会发生这种情况,但这与摄像机视图有关.
希望以上有所帮助.
| 归档时间: |
|
| 查看次数: |
2853 次 |
| 最近记录: |