简体   繁体   中英

Prob when rotating an uiimageview

When I am working with uiimageview, I want to rotate it with a small angle, and I did. But, in the border of uiimageview after rotating appears spikes, like a saw. I do not know why and try to fix it but I cant. Please help me.

Couple of options..

1) If you are using Core Graphics functions to rotate you can enable anti alias options

CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);

2) Add a 1 pixel transparent border to the your image on all 4 sides.

One more thing, there is a technical term to the spikes you saw and it is aliasing. And the techniques to prevent aliasing are called anti aliasing techniques. Hope this helps.

Thanks all you guys :) My friend showed me another way to fix it. I think this way is better than using transparent border trick. He changed an attribute in info plist file, that is "Renders with edge antialisasing", to YES. And everything becomes okay :). I hope it will help someone get a same prob with me :)

Take a UIView as subView and Place UIImageView on subView. Keep the size of subView and UIImageView Same.

Now, Use "UIViewAnimationTransitionFlipFromRight" or "UIViewAnimationTransitionFlipFromLeft" with Timer.

What you can do easily is to add a 1px transparent border around your image. So if your image is, let's say, 50x50 pixels you need to make it 52x52 such that the outer pixels are transparent. When you will rotate it should look fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM