iPhone动画:如何抗锯齿?

发布于 2024-08-07 04:49:28 字数 358 浏览 2 评论 0原文

我在 iPhone 应用程序中查看一些动画,感觉有点难看。然后我明白了:它只是不通过子像素状态进行动画处理。

所以,如果我使用通常的+beginAnimations/+commitAnimations,将一些东西移动几个像素看起来“跳跃”。我怎样才能避免它?是否有任何标志可以通过浮动坐标或其他方式使其具有动画效果?

只是为了让您了解我所拥有的和我正在寻找的内容,请参阅图片:

替代文本 http://www.ptoing.net/subpixel_aa.gif

提前致谢, 安东

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'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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稍尽春風 2024-08-14 04:49:28

这很有趣,但我发现 UIImageView 使用抗锯齿为其内容设置动画,而视图的边缘没有抗锯齿(硬)。这似乎是因为 UIView 本身应该保持相同的边界,而子像素渲染可能会稍微增加边界。

所以,我最终只是在图片周围放置了一些透明空间的图像,一切都很顺利。

只是不要让 UIView 为你剪切它的内容:)

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 :)

如果没结果 2024-08-14 04:49:28

您可以尝试从自定义 UIView 派生动画项目,该 UIView 重写其 drawRect 方法并为其设置抗锯齿功能,然后让父项绘制到其中。大致意思是:

- (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);
}

另一方面,当您到达这里时,渲染管道可能已经太晚了,因此您可能必须最终滚动自己的动画方案,以让您完全控制像素定位。

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.

一场春暖 2024-08-14 04:49:28

根据上面 Jeeva 的评论,您可以通过将 info.plist 中的以下选项设置为 YES,使 UIView 边缘使用抗锯齿进行渲染。

Renders with edge antialiasing

这是 Jeeva 指向的链接:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文