使用图像序列制作开关动画

发布于 2024-12-20 11:04:44 字数 182 浏览 1 评论 0原文

我想知道如何解决我遇到的问题。我有一个图像序列,基本上可以对开关进行动画处理。

在此处输入图像描述

我想在 iOS 中实现此功能。你会如何建议我去做呢?也许使用 UIButton?或者更确切地说是 UISwitch?

I would like to know how to solve a problem I'm having. I have an image sequence that basically animates a switch.

enter image description here

I'd like to implement this in iOS. How would you advise me to go for that? Maybe using UIButton? Or rather UISwitch?

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

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

发布评论

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

评论(2

[旋木] 2024-12-27 11:04:44

对于一个相当简单的解决方案(点击开关,无法滑动),我建议您使用堆叠的两个 UIView。

-1- 在底部,使用 UIImageView 来运行图像动画。

-2- 在顶部,使用 UIControl 来捕获 touché-up-inside 事件。

或者,您可以使用 UITapGestureRecognizer 代替 -2-。仅当生成的控件不用于 iOS <> 时才应考虑后一个选项。 3.2.

一旦您的点击识别器(UIControlUITapGestureRecognizer)收到点击事件,您只需播放通过 UIImageView 提供的动画即可。

有关使用 UIImageView 的动画的更多详细信息,请参阅其类参考,特别是诸如animationImages(图像数组)之类的内容。

由于 UIImageView 不为您提供反向动画功能,因此您必须在动画回到开始之前以相反的顺序分配图像(即在用户打开之后,现在切换回关闭)。

对于更复杂的解决方案(点击开关,可以滑动),您可以将 UISwipeGesture Recognizer 添加到自定义控件,并使用该 UIGestureRecognizer 的状态来选择当前可见的UIImageView 的图像。

For a rather simple solution (tap switches, no swiping possible), I would advise you to use two UIViews stacked.

-1- At the bottom, use a UIImageView which allows you to run image animations.

-2- At the top, use a UIControl which will capture the touché-up-inside events.

Alternatively, you could use a UITapGestureRecognizer as a replacement for -2-. The latter option should only be considered if the resulting control will not be used for iOS < 3.2.

As soon as your tap-recognizer (UIControl or UITapGestureRecognizer) receives the tap-event, you simply play the animation provided through your UIImageView.

For more details on animations using UIImageView see its class reference, specifically on things like animationImages (an array of images).

As UIImageView does not provide you with a reverse animation feature, you will have to assign the images in the reverse order before animating back to the start (that is after a user switched it on and now switches back to off).

For a more complex solution (tap switches, swiping is possible), you may add a UISwipeGesture Recognizer to your custom control and use the status of that UIGestureRecognizer to select the currently visible image of your UIImageView.

泪痕残 2024-12-27 11:04:44

iOS 5 允许您制作动画 UIImage。您可以将动画 UIImage 直接放入 UIButton 中,并在按下按钮时为其设置动画。 动画 UIImage

iOS 5 allows you to make animated UIImages. You can put the animated UIImage right into the UIButton and animate it on button presses. Animated UIImage

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