使用自定义Segue轻扫手势

时间:2014-08-10 00:11:01

标签: ios objective-c segue swipe gesture

我目前在故事板中使用模态segue使用按钮从一个视图转到另一个视图。在回来的路上我使用一个按钮来运行我的ABCustomSegue自定义segue。一切正常我只想在用户预先滑动后运行此自定义segue。我怎么能实现这个目标?

ABCustomSegue:

-(void)perform{
    UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
    [sourceViewController.view addSubview:destinationViewController.view];
    [destinationViewController.view setFrame:sourceViewController.view.window.frame];
    [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)];
    [destinationViewController.view setAlpha:1.0];

    [UIView animateWithDuration:0.4
                          delay:0.0
                        options:UIViewAnimationOptionTransitionFlipFromBottom
                     animations:^{
                         [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                         [destinationViewController.view setAlpha:1.0];
                     }
                     completion:^(BOOL finished){
                         [destinationViewController.view removeFromSuperview];
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                     }];
}

当前滑动识别器:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIScreenEdgePanGestureRecognizer *bezelSwipeGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeBack:)];
    bezelSwipeGestureRecognizer.edges = UIRectEdgeTop;
    bezelSwipeGestureRecognizer.delegate = self;
    [self.view addGestureRecognizer:bezelSwipeGestureRecognizer];

    UIView *invisibleScrollPreventer = [UIView new];
    invisibleScrollPreventer.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
    [self.view addSubview:invisibleScrollPreventer];

}

-(void)swipeBack:(UIScreenEdgePanGestureRecognizer *)recognizer
{
    if (recognizer.state == UIGestureRecognizerStateEnded) {

        NSLog(@"swipe back");

    }
}

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这段代码:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
相关问题