Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a Scale AffineTransform to a UIView changes its center

I'm running this code to shrink a UIView when the user taps on its superview. However, when applying the CGAffineTransformScale(), it also changes the centre. Is that the expected behaviour?

-(void) onTap:(UITapGestureRecognizer *)tap{


    [UIView animateWithDuration:1.2
                          delay:0
                        options:0
                     animations:^{
                         CGAffineTransform transform = self.icon.transform;
                         NSLog(@"Previous center: %@", NSStringFromCGPoint(self.icon.center));

                         self.icon.transform = CGAffineTransformScale(transform, 0.5, 0.5);

                         NSLog(@"Next center: %@", NSStringFromCGPoint(self.icon.center));
                     } completion:^(BOOL finished) {
                         //
                     }];


}
like image 758
cfischer Avatar asked Dec 26 '22 17:12

cfischer


1 Answers

I finally found out what was going on: Autolayout was repositioning the subview and changing the center.

like image 68
cfischer Avatar answered Dec 31 '22 12:12

cfischer