要素がスライドするようにビューをスライドさせたいUIScrollView
。ユーザーはビューに触れて引っ張ることができ、加速度と位置に応じて、ビューが離れたり留まったりします。
UIPanGestureRecognizer
と一緒に使用する必要がありUISwipeGestureRecognizer
ますか?
要素がスライドするようにビューをスライドさせたいUIScrollView
。ユーザーはビューに触れて引っ張ることができ、加速度と位置に応じて、ビューが離れたり留まったりします。
UIPanGestureRecognizer
と一緒に使用する必要がありUISwipeGestureRecognizer
ますか?
コンテンツをユーザーの指に追従させたい場合は、 UIPanGestureRecognizerを使用します (ここで行うように聞こえます)。スワイプジェスチャーは、スワイプが完了するのを待ってから、それについて教えてくれます。
'state' プロパティを使用して開始時と終了時の指の位置を取得し、速度を使用して加速度を決定します。
CGPoint location = [sender locationInView:self.view];
if(sender.state == UIGestureRecognizerStateBegan)
{
startLocation = location;
}
else if(sender.state == UIGestureRecognizerStateChanged)
{
// Move view or do something to give feedback to user while they swipe
}
else if(sender.state == UIGestureRecognizerStateEnded)
{
CGPoint distanceMoved = CGPointMake(location.x - startLocation.x, location.y - startLocation.y);
CGPoint velocity = [sender velocityInView:self.view];
// Logic goes here
}