开发者

How to properly transform a UIView with a custom drawRect method

开发者 https://www.devze.com 2023-01-07 12:39 出处:网络
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.

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 t开发者_StackOverflow社区ry 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?
0

精彩评论

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