円の形をしており、次のコードで回転させてtouchesBegan(touches:, withEvent:)
とtouchesMoved(touches:, withEvent:)
を上書きします。回転速度を計算し、iOSビューを自然回転させます
var deltaAngle = CGFloat(0)
var startTransform: CGAffineTransform?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
let touchPoint = touches.first!.locationInView(view)
let dx = touchPoint.x - view.center.x
let dy = touchPoint.y - view.center.y
deltaAngle = atan2(dy, dx)
startTransform = arrowPickerView.transform
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)
{
let touchPoint = touches.first!.locationInView(view)
let dx = touchPoint.x - view.center.x
let dy = touchPoint.y - view.center.y
let angle = atan2(dy, dx)
let angleDifference = deltaAngle - angle
let transform = CGAffineTransformRotate(startTransform!, -angleDifference)
arrowPickerView.transform = transform
}
は、私は自然に(連続スクロールに似て)少し回転速度を計算し、ビューを持っているtouchesEnded(touches:, withEvent:)
を上書きしたいです。私は現在、元の変換を保存し、デルタの角度を計算します。これをどのように実装できますか?前もって感謝します!
速度は時間で除算されます。したがって、touchesBeganとtouchesEndにNSDate()。timesince1970を追加すると、beginイベントとendイベントの間の秒数を計算できます。距離は単にsqrt(dx^2 + dy^2)です。それともあなたが探している速度ではないのですか?それ以外の回答は以下のように書き直してください:) – Emptyless
私は運動スクロールを処理してスクロールを続けるようにしていました。ユーザーが超高速スクロールしてから実際にスロースクロールすると、それは回転していた最後のスピードよりも速いスピードで回転し続けます。私は質問の速度に重点を置いたが、運動スクロールについてはすべて –