gpt4 book ai didi

ios - 有什么方法可以检测手机平放时的角度吗?

转载 作者:行者123 更新时间:2023-11-28 23:32:05 24 4
gpt4 key购买 nike

有什么方法可以获取手机的当前角度,即使手机处于纵向锁定状态并试图通过右手(横向)位置或左手位置(横向)握住它来捕捉图像?

每当我通过右手位置拍摄图像(将主页按钮保持在右侧)时,我都能正确获取图像,但每当我通过左手位置拍摄图像时,我都会得到倒置图像(图像旋转 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com