How can i rotate an arrow image by touch on that image?(如何通过触摸该图像来旋转箭头图像?)
问题描述
我正在做一个项目,我需要通过触摸来旋转图像.
I am working on a project where i need to rotate an image by touching it.
根据用户的触摸方式,它可以更快或更慢地旋转.
It can be rotate faster or slower depending on how the user touches it.
你能告诉我一些教程或如何做到这一点吗?
Can you show me some tutorials or how this can be done?
推荐答案
将你的图像放在 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.
这篇关于如何通过触摸该图像来旋转箭头图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过触摸该图像来旋转箭头图像?


基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01