Applying a Scale AffineTransform to a UIView changes its center

cfischer picture cfischer · Sep 20, 2012 · Viewed 10k times · Source

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


}

Answer

cfischer picture cfischer · Oct 17, 2012

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