关于iphone:<Error>:CGAffineTransform Inverse:奇异矩阵

<Error>: CGAffineTransformInvert: singular matrix

我正在尝试在视图上执行此动画,将其缩放到 (0,0),然后使用 CGRectMake 方法移动此帧并将其缩放回 (1,1)。
所以我用下面的代码来做这个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-(void)startWalkAnimationStartWalkingBtnViewScaleToZero{
    CGAffineTransform transform = StartWalkBtnView.transform;

    StartWalkBtnView.transform=CGAffineTransformScale(transform,1.0f, 1.0f);
    [UIView animateWithDuration: 0.7
                          delay: 0.6
                        options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                     animations:^{ StartWalkBtnView.transform = CGAffineTransformScale(transform, 0.0f, 0.0f);
                     }
                     completion:^(BOOL finished){
                         [UIView animateWithDuration:0.0
                                               delay:0.0
                                             options: UIViewAnimationOptionCurveEaseIn
                                          animations:^{
                                              StartWalkBtnView.frame=CGRectMake(92, 270, 120, 121);
                                          }
                                          completion:^(BOOL finished){

                                              StartWalkBtnView.transform=CGAffineTransformScale(transform,0.0f, 0.0f);
                                              [UIView animateWithDuration: 0.7
                                                                    delay: 0.8
                                                                  options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                                                               animations:^{ StartWalkBtnView.transform = CGAffineTransformScale(transform, 1.0f, 1.0f);
                                                               }
                                                               completion:^(BOOL finished){}
                                               ];
                                          }];
                     }
     ];
}

但是在尝试运行此动画后,我在控制台中收到以下错误。

1
Jun 17 12:02:49 Kareem.local MyAppName[3157] <Error>: CGAffineTransformInvert: singular matrix.

我在谷歌上搜索了太多,并尝试了所有提供的解决方案(接近零值的规模,...)但没有任何效果,有人有解决这个问题的想法。
感谢您的帮助

更新:
我发现问题在以下行:

StartWalkBtnView.frame=CGRectMake(92, 270, 120, 121);

但实际上我不知道如何解决问题,但是当我删除此行时它缩放为零然后正常从零返回而没有任何错误


您收到此错误是因为您的缩放矩阵的行列式为零。当您尝试将变换更改为比例 1.0 时,Core Graphics 会尝试找到您之前变换的逆矩阵以将变换返回到单位矩阵。对于行列式 0,这会导致不可逆矩阵,这就是您收到此错误的原因。不要将比例转换为 0.0.

您确定您现在在设置为 0.0 的两个比例中都检查了接近零的值吗?

编辑(答案):

  • 因此,根据 Raj 的评论,为了避免此错误,您必须尝试一个不等于零(但非常接近于零)的值。

即代替:

1
(transform,0.0f, 0.0f);

试试:

1
(transform,0.01f, 0.01f);

1
(transform,0.001f, 0.001f);


网页的内容可能是导致此错误的原因,而不是您的 iOS 应用程序编程。

我发现只有在 Yahoo 上时,我的应用才会出现错误。 Google.com,没问题。 Reuters.com,没问题。 SeattleTimes.com,没问题。回到Yahoo.com,问题。特别是在滚动时,错误可能会在一瞬间出现几次。

在我的博客上有更多详细信息。