繁体   English   中英

CGAffineTransformMakeRotation(M_PI_2)在控制台中生成错误:CGAffineTransformInvert:奇异矩阵

[英]CGAffineTransformMakeRotation(M_PI_2) generate error in console: CGAffineTransformInvert: singular matrix

我第一次转动iphone时会转动按钮。 我第二次转iphone失败了。

- (void)configureViewsLandscapeMode
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {

        [self.button setTransform:CGAffineTransformMakeRotation(M_PI_2)];

    } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {


        [self.button setTransform:CGAffineTransformMakeRotation(-M_PI_2)];

    }
}

我读了其他类似的答案:

UIView使用CGAffineTransformMakeScale缩放为0

CGAffineTransformInvert:奇异矩阵

我从IOS开始,我不明白这个问题。 我想了解问题而不是解决问题,我将不胜感激

尝试这个 :

- (void)configureViewsLandscapeMode
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {

        [self.button setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, M_PI_2)];

    } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {


        [self.button setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI_2)];

    }
}

制作旋转动画时,请确保不要更改视图frame 例如,当使用自动调整大小或尝试明确更改frame时,可能会发生这种情况。

如果您同时更改帧和变换,尤其是在动画内部,iOS会尝试从原始位置生成动画到目标位置。 这涉及一些矩阵计算,如果涉及多个变化(例如frame ),则可能以错误结束。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM