簡體   English   中英

如何在iOS中使用Pan Gesture Recognizer在視圖之間切換?

[英]How to switch between views using Pan Gesture Recognizer in iOS?

我有兩個視圖,我想使用“向右”手勢(例如Facebook ios應用程序中使用的手勢)來切換到第二個視圖。 開始使用平移手勢后,視圖應該開始發生變化。我該如何執行此操作? 有人有執行此操作的示例代碼嗎?

有一個帶有示例項目的git,您可以通過它引用Facebook iOS應用程序中的側面菜單效果。

https://github.com/BenHall/ios_facebook_style_navigation

編輯:

好的,然后嘗試如下操作:

   UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewSwipedLeft:)];
   [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
   [self.navigationController.navigationBar addGestureRecognizer:swipeLeft];

然后使用以下方式處理滑動:

-(void) didSwipedLeft: (UISwipeGestureRecognizer *) gesture {

  if (gesture.state != UIGestureRecognizerStateEnded) {
      return;
  }

  //do something    
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM