2012-10-29 68 views
0

我想滑動我的看法像元素滑動UIScrollView。用戶可以觸摸查看和拉動,並且根據加速度和位置,視圖應該離開或停留。如何創建像UIScrollView幻燈片

我是否應該使用UIPanGestureRecognizerUISwipeGestureRecognizer

+1

'UIPanGestureRecognizer' – atxe

+0

使用的UIScrollView爲什麼重新發明輪子? – jithinroy

回答

0

你想用UIPanGestureRecognizer,如果你想要的內容按照用戶的手指(聽起來像你在這裏做的)。滑動手勢將等待滑動完成,然後告訴你。

使用「狀態」屬性獲取手指在啓動時的位置,以及完成時的位置,並使用速度確定加速度。

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 
}