I have a transparent png inside a UIImageView ( self.myImage ) that I want to rotate around its center point. The code should be pretty simple:
[self.myImage.layer setAnchorPoint:CGPointMake(0.5, 0.5)]; [UIView animateWithDuration:1.0 animations:^{ [self.myImage setTransform:CGAffineTransformMakeRotation(angle)]; }];
The image rotates at the correct speed / time and at right angles, but its position shifts. Here is an example of what is happening:

The gray square just shows the position on the screen. Transparent png (contained in UIImageView) is a different shape. White dashed lines show the center of the UIImageView. The initial position of the image is displayed on the left side of the image, the image after rotation is displayed on the right using the code above (which moves slightly to the right). Black and white circles are in the center of the image file.
Is there something I am missing? As far as I understand, the first line above is not required, because these are the default values. Should I install / uninstall something in the storyboard / programmatically?
ios objective-c iphone uiimageview cgaffinetransform
Eric
source share