gpt4 book ai didi

iOS从旋转 View 中截取 "homebutton + powerbutton"屏幕截图是颠倒的

转载 作者:行者123 更新时间:2023-12-01 16:42:13 24 4
gpt4 key购买 nike

当用户按下主页按钮和电源按钮进行屏幕截图时,屏幕截图会上下颠倒。设备从不自动旋转。我观察 UIDeviceOrientationDidChangeNotification如果它是横向的,我将显示旋转的 View 。取决于左或右设备方向

当我显示使用此代码旋转的 View 时会发生这种情况

CGAffineTransform rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_TO_RADIANS(90));
landscape.transform = rotationTransform;

下面是viewcontroller的旋转方法
- (BOOL)shouldAutorotate {
return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

我禁用自动旋转并强制旋转:
- (void)forceOrientationChange {
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
CGAffineTransform rotationTransform = CGAffineTransformIdentity;
switch (deviceOrientation) {
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationPortrait:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
break;
case UIDeviceOrientationLandscapeLeft: {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_TO_RADIANS(90));
landscape.transform = rotationTransform;
break;
}
case UIDeviceOrientationLandscapeRight: {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_TO_RADIANS(-90));
landscape.transform = rotationTransform;
break;
}
default:
break;
}
}

最佳答案

我刚刚将 UIInterfaceOrientationLandscapeLeft 切换到 UIInterfaceOrientationLandscapeRight

- (void)forceOrientationChange {
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
CGAffineTransform rotationTransform = CGAffineTransformIdentity;
switch (deviceOrientation) {
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationPortrait:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
break;
case UIDeviceOrientationLandscapeLeft: {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_TO_RADIANS(90));
landscape.transform = rotationTransform;
break;
}
case UIDeviceOrientationLandscapeRight: {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_TO_RADIANS(-90));
landscape.transform = rotationTransform;
break;
}
default:
break;
}
}

关于iOS从旋转 View 中截取 "homebutton + powerbutton"屏幕截图是颠倒的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23288722/

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