How to rotate image around center point automatically with finger touch

前端 未结 3 550
小蘑菇
小蘑菇 2021-01-17 04:38

On iPhone, how to implement rotating image around the center point using finger touch ?

Just like wheel, if you put finger on the iPhone screen , then move suddenly,

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 05:20

    The transform property of a view or layer can be used to rotate the image displayed within. As far as the spinning part goes, you just track the location and movement of touches in your view with touchesBegan, touchesMoved, and touchesEnded.

    Use the distance and time between the touches updates to calculate a speed, and use that to set a rotational velocity. Once you start the image spinning, update the position periodically (with an NSTimer, maybe), and reduce the rotational velocity by some constant.

提交回复
热议问题