如何使用自定义的drawRect方法正确转换UIView
我编写了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论