Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView "squashed" after CGAffineTransformMakeRotation

I have a UIImageView which is inside another UIView.

I rotate the UIImageView with something like:

 object.transform=CGAffineTransformMakeRotation(angle)

When the outer UIView is not rotated, and can use CGAffineTransformMakeRotation to rotate the UIImageView, and it works properly.

However, When the outer UIView is rotated, and I then rotate the UIImageView (non-zero "angle" above) - the UIImageView appears "squashed" or "flattened".

This seems to constantly get worse and worse as it is rotated through different angles.

Why is this happening? Is the outer UIView modifying the transformation matrix that I am then modifying again by explicity setting it?

How can I rotate a UIImageView within a rotated UIView and have it just rotate correctly?

like image 772
Brad Avatar asked Aug 24 '11 17:08

Brad


2 Answers

Maybe your UIIamgeView is autoresized by it's superview.

You can try disable the autoresizing ability by setting:

imageView.autoresizingMask = UIViewAutoresizingNone;

or if you just do not want iOS to automatically change the size of your imageView but still want it to automatically set the position for you, you can call:

imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;

Tell me if you still have problem.

like image 103
xuzhe Avatar answered Nov 18 '22 13:11

xuzhe


Antialiasing is the process whereby a view’s edges are blended with the colors of the layer below it. Antialiasing for view edges can be enabled systemwide by setting the UIViewEdgeAntialiasing flag in your app’s info.plist, but as the documentation warns, this can have a negative impact on performance (because it requires Core Animation to sample pixels from the render buffer beneath your layer in order to calculate the blending).

Renders with edge antialisasing = YES

like image 44
Gaurav Avatar answered Nov 18 '22 13:11

Gaurav