具有可拉伸图像的 iPhone 动画

发布于 2024-09-05 06:03:26 字数 546 浏览 1 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(1

南街女流氓 2024-09-12 06:03:26

在翻阅一些 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.

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