2014-07-14 63 views
0

我知道有很多這樣的問題和GitHub上的許多庫的答案,但我只是想讓它保持輕鬆和簡單。我只想將菜單移出並使其跟隨我的手指。該部分的作品,但視圖不會順利滑出......它只是出現在我的手指。下面是我有:UIPanGestureRecognizer滑動UIView動畫

//viewDidLoad 
UIPanGestureRecognizer *panSettings = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)]; 
[panSettings setDelegate:self]; 
[self.view addGestureRecognizer:panSettings]; 

UIView *container = [[UIView alloc]initWithFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
//...drop shadows and such... 
[self.view addSubview:_container]; 

- (void)handlePan:(UIPanGestureRecognizer *)sender{ 
    CGPoint velocity = [sender velocityInView:self.view]; 
    CGPoint translation = [sender translationInView:self.view]; 
    if (velocity.x < 0 && translation.x < -50) { 
     if (_container.frame.origin.x != 0) { 
      panCoord = [sender locationInView:self.view]; 
      [UIView animateWithDuration:0.3 animations:^{ 
       _container.frame = CGRectMake(panCoord.x-100, 0, self.view.frame.size.width, self.view.frame.size.height); 
      }]; 
     } 
    } 
} 

處理鍋:我想確認滑動將會哪種方式,檢查多長時間和檢查集裝箱的位置。我想讓滑動順利地滑到手指位置,一旦滑動離開更遠的負值,然後-50 ...任何建議?

+0

哪裏是你的UIView動畫? –

+0

@SantaClaus我用UIView動畫也嘗試過它,它仍然具有剛出現在手指位置的相同效果。 – denikov

+1

你也可以使用觸摸方法(即觸摸開始,觸摸移動,觸摸結束) –

回答

1

我用:

UISwipeGestureRecognizer *sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightRevealToggle:)]; 
    sgr.direction = UISwipeGestureRecognizerDirectionRight; 
    [self.view addGestureRecognizer:sgr]; 

檢查出來也許更容易

+0

謝謝,我明白那會更容易,但是這會破壞能夠在屏幕上拖動視圖的目的。 – denikov

+0

但你可以同時添加.. –