xi.lin xi.lin - 1 year ago 280
Objective-C Question

Is there any callback for swipe back gesture in iOS?

Sometimes when user go back to the previous

, I want to do something.

If the user clicked the back button in
, I can capture the event.

But if they use the swipe back gesture to go back, I cannot respond to the change.

So is there any callback for swipe back gesture?

Currently I can only disable this kind of page in my app through

interactivePopGestureRecognizer.enabled = NO;

Answer Source

Try this.It gives you some what better solution.

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScreenEdgePanGestureRecognizer *gesture = (UIScreenEdgePanGestureRecognizer*)[self.navigationController.view.gestureRecognizers objectAtIndex:0];
        [gesture addTarget:self action:@selector(moved:)];

In Target method.

    // do what you want

//finally remove the target
    [[self.navigationController.view.gestureRecognizers objectAtIndex:0] removeTarget:self action:@selector(moved:)];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download