【问题标题】:iOS take "homebutton + powerbutton" screenshot from rotated view is upside downiOS从旋转视图中截取“主页按钮+电源按钮”的屏幕截图是颠倒的
【发布时间】:2014-04-25 09:05:29
【问题描述】:

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

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

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;
    }
}

【问题讨论】:

  • 但是你从不改变界面方向?
  • 嗨大卫,我更新了我的问题。

标签: ios rotation core-graphics screenshot


【解决方案1】:

我刚刚将 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;
    }
}

【讨论】:

    猜你喜欢
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 2013-01-24
    相关资源
    最近更新 更多