简体   繁体   English

触摸校准转速

[英]Calibrate rotation speed with touch

I'm rotating a view using the following way: 我使用以下方式旋转视图:

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
        for touch in touches{
        rotatableView.transform = CGAffineTransformMakeRotation(degreesToRadian(i++))
        }
    }

By anyway can I calibrate this rotation with the speed of moved touches? 无论如何,我可以通过移动的触摸速度来校准此旋转吗?

As i understood , you want your UIImageView to rotate as fast as your finger , in other words , you mean that , "how fast my finger moves , is how fast the rotation is " . 据我了解,您希望UIImageView的旋转速度与手指一样快,换句话说,您的意思是“手指移动的速度多快,旋转的速度有多快”。

in that sense , here is the code 从这个意义上讲,这是代码

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
    let t = touches.anyObject() as UITouch
    let position = t.locationInView(self.view)

    let target = rotatableView.center        
    let angle = atan2(target.y-position.y , target.x-position.x)
    rotatableView.transform = CGAffineTransformMakeRotation(angle)

}

atan2 is a mathmatical function , you can read more about it here atan2是一个数学函数,您可以在此处了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM