2017-04-24 6 views
0

panGestureを使用して左にスワイプする(左にパンする)ようにView Controllerをプッシュするにはどうすればよいですか? 現在、SwipeRightToPopController githubライブラリーを使用して、パンニングの右側にポップビューコントローラーを実現しています。左のスワイプでビューコントローラをプッシュ

+0

私はそれをテストしていないで、この

のようにしてみたが、これは、あなたがやりたいように見えます:https://github.com/robertmryan/ScreenEdgeGestureNavigationController – DonMag

+0

は誰投稿者に-1を与えるこれらの人 –

答えて

0

これを試してくださいのviewDidLoadで

UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)]; 
[self.view addGestureRecognizer:swipeLeftGesture]; 
swipeLeftGesture.direction=UISwipeGestureRecognizerDirectionLeft;// change direction as per your needs 

その選択方法:

-(void)handleSwipeGesture:(UIGestureRecognizer *) sender 
{ 
    NSUInteger touches = sender.numberOfTouches; 
    if (touches == 2) 
    { 
     if (sender.state == UIGestureRecognizerStateEnded) 
     { 
      //push view controller here  
     } 
    } 
} 

使用パンジェスチャ

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)]; 
[self.view addGestureRecognizer:panRecognizer]; 

- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer 
{ 
    CGPoint velocity = [panRecognizer velocityInView:self.view]; 

    NSLog(@"Pan Detected."); 

    if (velocity.x > 0) 
    { 
     NSLog(@"Pan went right."); 
    } 
    else 
    { 
     NSLog(@"Pan went left.");  

     if (panRecognizer.state == UIGestureRecognizerStateChanged) 
      NSLog(@"push here "); 

     [self performSegueWithIdentifier:@"Settings" sender:panRecognizer]; 
    } 
} 
+0

あなたの努力に感謝しますが、これは指で行かないでしょう、私はビューコントローラを押しながら感じのパンジェスチャータイプをしたいです 例:極端な左から右のビューポップアウトを取得 –

1

のviewDidLoad

let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes)) 
let rightSwipe = UISwipeGestureRecognizer(target: self, action:#selector(handleSwipes)) 

leftSwipe.direction = .left 
rightSwipe.direction = .right 

view.addGestureRecognizer(leftSwipe) 
view.addGestureRecognizer(rightSwipe) 

func handleSwipes(sender:UISwipeGestureRecognizer) { 
    if (sender.direction == .left) 
    { 
     let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "FirstViewController") as UIViewController 
     self.navigationController?.pushViewController(initialViewControlleripad, animated: false) 
    }if(sender.direction == .right){ 

     let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "SecondViewController") as UIViewController 
     self.navigationController?.pushViewController(initialViewControlleripad, animated: false) 
    } 
} 
+0

あなたの努力のおかげで、しかし、これは指で行くことはありません、私は表示コントローラーを押しながらパンジェスチャーのタイプを感じたい 例:極端な左から右にスワイプするとポップアウトが表示される –

関連する問題