如何使用自定义的drawRect方法正确转换UIView

发布于 2024-09-08 19:52:02 字数 387 浏览 0 评论 0原文

我编写了一个 UIView 子类,它在 png 图像下方添加了一个漂亮的软阴影。我正在重写 drawRect 方法来绘制图像并添加阴影。

现在,当我尝试在 UIView 上进行缩放/旋转仿射变换(通过调用 .transform 方法)时,由于 drawRect 方法的初始“扁平化”,我没有得到我正在寻找的结果。

我想“重绘”阴影,以便在缩放时保持相同的偏移量。我尝试重写变换方法并重绘图像,但没有成功。

我想知道我目前的方向是否正确。

  • 我真的应该重新绘制图像并创建复杂的 CG 变换并每次都添加阴影吗?
  • 这是一种重新绘制事物的高效方式吗?
  • 变换方法似乎调整了整个容器的大小,混合了整个图像的抗锯齿,导致锯齿状边缘。对此有什么想法吗?

I've written a UIView subclass which adds a nice soft shadow underneath a png image. I'm overriding the drawRect method to draw the image and add the shadow.

Now, when I try to do a scale/rotate-affine transform on the UIView (by calling the .transform method), I'm not getting the result I'm looking for due to the initial "flattening" of the drawRect method.

I'd like to "redraw" the shadow so that it stays at the same offset when scaling. I tried to override the transform method and redraw the image but without success.

I was wondering if I'm currently looking in the correct direction.

  • Should I actually redraw the image and create complicated CG transforms and add the shadow every time again?
  • Is this a performant way of redrawing things?
  • The transform method seems to resize the whole container, mixing up the anti-aliassing of the whole image, resulting in jagged edges. Any thoughts on that?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文