2017-04-24 113 views
0

如何使用panGesture向左滑動視圖控制器(平移左側)? 目前使用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

感謝您的努力,但這不會用手指去,我想要一個平移手勢類型的感覺,同時推視圖控制器 例如:當你從極端的左側滑動到右側視圖得到彈出 –

相關問題