CGAffineTransformMakeRotation(M_PI_2)在控制台上产生错误:CGAffineTransformInvert:奇异矩阵。

时间:2021-02-18 07:22:21

The first time I turn my iphone turns the button. The second time I turn the iphone fails.

我第一次打开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)];

    }
}

I read others similar answers:

我读了一些类似的答案:

UIView scale to 0 using CGAffineTransformMakeScale

使用CGAffineTransformMakeScale将UIView缩放到0。

CGAffineTransformInvert: singular matrix

CGAffineTransformInvert:奇异矩阵

I'm starting with IOS and I do not understand the problem. I would like to understand the problem more than having a solution, I would appreciate some guidance

我从IOS开始,我不理解这个问题。我想要理解这个问题比有一个解决方案,我会感激一些指导。

2 个解决方案

#1


1  

When making a rotation animation, make sure you are not changing view frame. That can happen for example when autoresizing is used or when you are trying to change frame explicitely.

在做旋转动画时,确保你没有改变视图框架。这可能发生在当自动调整被使用时或者当你试图明确地改变框架时。

If you change frame and transform at the same time, especially inside an animation, iOS tries to generate an animation from the original position to the target position. That involves some matrix calculations and that can end in an error if multiple changes (e.g. frame) are involved.

如果你同时改变帧和转换,特别是在动画中,iOS会尝试从原始位置生成动画到目标位置。这涉及到一些矩阵计算,如果涉及到多个变化(例如框架),就会导致错误。

#2


1  

Try this :

试试这个:

- (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)];

    }
}

#1


1  

When making a rotation animation, make sure you are not changing view frame. That can happen for example when autoresizing is used or when you are trying to change frame explicitely.

在做旋转动画时,确保你没有改变视图框架。这可能发生在当自动调整被使用时或者当你试图明确地改变框架时。

If you change frame and transform at the same time, especially inside an animation, iOS tries to generate an animation from the original position to the target position. That involves some matrix calculations and that can end in an error if multiple changes (e.g. frame) are involved.

如果你同时改变帧和转换,特别是在动画中,iOS会尝试从原始位置生成动画到目标位置。这涉及到一些矩阵计算,如果涉及到多个变化(例如框架),就会导致错误。

#2


1  

Try this :

试试这个:

- (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)];

    }
}