Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<Error>: CGAffineTransformInvert: singular matrix

Am trying to do this animation on a view, To Scale it to (0,0) then Move this frame using CGRectMake method and scale it back to (1,1). So I used the following Code to do this

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

But After trying to run this Animation I got the following error in the Console.

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

I googled for this too much, and have tried all the solutions provided (Scale Near to zere Value,...) but nothing worked, Do any one has an idea for solving this. Thanks for help

UPDATE: I found that the problem in the following line:

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

But Actually I don't know how to solve the problem, But when I removed this line It scaled to zero then back from zero normally without any errors

like image 866
Kareem Waheed Avatar asked Jun 17 '13 10:06

Kareem Waheed


2 Answers

You get this error because the determinant of your scaling matrix is zero. When you attempt to change the transform to scale 1.0, Core Graphics tries to find the inverse matrix of your previous transformation to return the transformation to identity matrix. With determinant 0 this results in a non-inversible matrix, and that's why you get this error. Don't transform scale to 0.0.

Are you sure you checked with near zero values in both scalings you set to 0.0 now?

Edit (Answer):

  • So, from Raj's comment, for avoiding this error, you have to try a value not equal to zero (but very near to zero).

That is, instead of:

(transform,0.0f, 0.0f);

Try:

(transform,0.01f, 0.01f);

or

(transform,0.001f, 0.001f);
like image 115
Alexander Avatar answered Nov 27 '22 05:11

Alexander


The content of the web page may be the cause of this error, not your iOS app programming.

I found the error occurred in my app only while on Yahoo. Google.com, no problem. Reuters.com, no problem. SeattleTimes.com, no problem. Back to Yahoo.com, problem. Especially while scrolling when the error may appear a few times in a split second.

More detail on my blog.

like image 40
Basil Bourque Avatar answered Nov 27 '22 06:11

Basil Bourque