且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过触摸该图像来旋转箭头图像?

更新时间:2022-06-04 06:49:51

将你的图像放在 UIImageView 中,然后子类化该视图并替换 touchesBegan:withEvent: 或为其设置一个委托并实现与委托方法相同的方法.这将使您能够响应触摸事件(在这种情况下是触摸的开始,尽管您可以为结束触摸或移动手指做同样的事情).

Place your image within a UIImageView, then either subclass that view and replace touchesBegan:withEvent: or set a delegate for it and implement the same method as a delegate method. This will give you the ability to respond to touch events (the beginning of a touch, in this case, although you can do the same for ending a touch or moving of the finger).

在这种触摸处理方法中,您可以实现类似于我描述的 这里以便以给定的速度对 UIImageView 执行启用 Core-Animation 的旋转.要更改速度,请更改我提供的动画的持续时间属性.正如我在那里建议的那样,您可能希望研究 CAKeyframeAnimation 以在开始和结束时使用加速和减速来制作更平滑的动画.

Within this touch handling method, you can implement something similar to what I describe here in order to perform a Core-Animation-enabled rotation of your UIImageView at a given speed. To alter the speed, change the duration property on the animation I provide. As I suggest there, you may want to look into a CAKeyframeAnimation to do a smoother animation with acceleration and deceleration at the beginning and end.