Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将视图控制器推到左侧滑动_Ios_Pushviewcontroller - Fatal编程技术网

Ios 将视图控制器推到左侧滑动

Ios 将视图控制器推到左侧滑动,ios,pushviewcontroller,Ios,Pushviewcontroller,如何使用Pangestrue在向左滑动(向左平移)时推送视图控制器? 当前正在使用SwipeRightToPopControllergithub库在平移右侧实现弹出视图控制器。尝试以下操作: 在视图中加载: UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)]; [self.vie

如何使用Pangestrue在向左滑动(向左平移)时推送视图控制器? 当前正在使用SwipeRightToPopController
github
库在平移右侧实现弹出视图控制器。

尝试以下操作:

在视图中加载:

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    
        }
    }  
}
其选择器方法:

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];
    }
}
像这样试试

在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)
     }
}

感谢您的努力,但这与手指无关,我希望在按下视图控制器时有一种平移手势的感觉,例如:当您从最左向右滑动视图时popout@MridulGupta我遇到了同样的问题要解决,你找到解决办法了吗?哦,是的,很久以前,现在我可以帮你解决这个@Guala。我会把解决方案贴在这张票子上谢谢,哪里可以找到解决方案@Mridulguptathank感谢您的努力,但这与手指不符,我希望在按下视图控制器时有一种平移手势的感觉,例如:当您从最左侧滑动到右侧时,视图会弹出,我还没有测试它,但这似乎是您想要的: