具有可拉伸图像的 iPhone 动画
我有一个 UIView 子类,它绘制 UIImage 作为背景。该图像是使用 stretchableImageWithLeftCapWidth:topCapHeight:
方法创建的,它具有圆形边缘。
我还使用一个动画块,在其中调整视图的大小。我希望在动画过程中,有时会调用drawRect:
方法,这将导致背景图像被正确绘制。
不幸的是,动画似乎渲染了图像,然后在动画过程中重新缩放它,这显然使以前的圆形边缘被严重拉伸。
我能想象的唯一解决方法是将三个单独的 UIImageView(顶盖、中间填充、底盖)放在原始背景图像上方,然后重新定位大写图像并缩放填充图像。然而,这似乎很复杂......
有什么更好的方法可以防止这种情况发生吗?
编辑:找到这个。听起来很糟糕...
I got a UIView subclass that draws a UIImage as its background. The image is created using the stretchableImageWithLeftCapWidth:topCapHeight:
method, it has round edges.
I also use an animation block inside of which I resize my view. I had hoped that during animation, the drawRect:
method would get called sometimes, which would result in the background image getting drawn correctly.
Unfortunately, the animation seems to render the image and then just rescale it during the animation, which obviously makes the formerly round edges getting nastily stretched.
The only workaround I can imagine is put three separate UIImageViews (top cap, middle fill, bottom cap) above my original background image and then reposition the caps images and scaling the fill image. However, this seems quite complicated...
Is there any better way I can prevent this from happening?
EDIT: Found this. Sounds bad...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在翻阅一些 Apple 文档时,我偶然发现了我的问题的解决方案。您所要做的就是使用 UIView 的
contentStretch
参数。它允许您手动指定在动画过程中拉伸的视图区域。While digging through some Apple docs, I coincidentally found the solution to my problem. All you have to do is play with UIView's
contentStretch
parameter. It allows you to manually specify the area of your view that gets stretched during animation.