开发者

iPhone Animation: how to anti-alias?

I was looking at some animations in my iPhone app and felt like it was kind of ugly. And then I undertsood it: it just doesn'开发者_JAVA技巧t animate through subpixel states.

So, in case I use usual +beginAnimations/+commitAnimations, moving some stuff just a few pixels look "jumpy". How can I avoid it? Are there any flags to make it animate through float coords or whatever?

Just to give you an idea of what I have and what I'm looking for, please refer to the picture:

alt text http://www.ptoing.net/subpixel_aa.gif

Thanks in advance, Anton


That's funny, but I found that UIImageView animate its content using aniti-aliasing, while edges of the view are not anti-aliased (hard). It seems to be because UIView itself should maintain the same bounds, while subpixel rendering might add to the bound a bit.

So, I ended up just putting an image with some transparent space around the picture, and it all went smooth.

Just don't let UIView cut its contents for you :)


You can try deriving the item you're animating from a custom UIView that overrides its drawRect method and sets anti-aliasing on for it then lets the parent draw into it. Something along the lines of:

- (void) drawRect:(CGRect)area
{
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSaveGState(context);
  CGContextSetShouldAntialias(context, true);
  CGContextSetAllowsAntialiasing(context, true);
  [super drawRect:area];
  // We have to turn it back off since it's not saved in graphic state.
  CGContextSetAllowsAntialiasing(context, false);
  CGContextRestoreGState(context);
}

On the other hand, it might be too late in the rendering pipeline by the time you get here, so you may have to end up rolling your own animation scheme that lets you have full control over pixel-positioning.


Per Jeeva's comment above, you can make UIView edges render with Anti-aliasing by settings the following option in the info.plist to YES.

Renders with edge antialiasing

Here is the link Jeeva pointed to:

http://www.techpaa.com/2012/06/avoiding-view-edge-antialiasing.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜