有什么方法可以获取手机的当前角度,即使手机处于纵向锁定状态并试图通过右手(横向)位置或左手位置(横向)握住它来捕捉图像?
每当我通过右手位置拍摄图像(将主页按钮保持在右侧)时,我都能正确获取图像,但每当我通过左手位置拍摄图像时,我都会得到倒置图像(图像旋转 180 度) .如何解决这个问题?
我试过了但是没有用,因为方向总是纵向的
UIDeviceOrientation orientation=[[UIDevice currentDevice] orientation];
// Do Orientation operations
if (orientation == UIDeviceOrientationLandscapeRight)
{
MYLog(@"LandRight");
rotation = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(90 * (M_PI/180))];
}
else if(orientation == UIDeviceOrientationLandscapeLeft){
MYLog(@"LandLeft");
rotation = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(-90 * (M_PI/180))];
}
else if(orientation == UIDeviceOrientationPortrait){
MYLog(@"porttttt");
rotation = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(0 * (M_PI/180))];
}
else if(orientation == UIDeviceOrientationPortraitUpsideDown)
{
MYLog(@"portupdown");
rotation = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(1 * (M_PI/180))];
}
else if(orientation == UIDeviceOrientationFaceUp)
{
MYLog(@"faceup");
rotation = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(-90 * (M_PI/180))];
}
[transform setValue:rotation forKey:@"inputTransform"];
enhancedImage = [transform outputImage];
任何更多的捕获都不应该旋转图像。
最佳答案
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape {
print("Landscape")
} else {
print("Portrait")
}
}
希望对你有帮助
关于ios - 有什么方法可以检测手机平放时的角度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56106132/