0
votes

If i am using gesture recognizer like this

 UISwipeGestureRecognizer *noRightShiftForVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)];
   [self.circleProgressBar addGestureRecognizer:noRightShiftForVolume];

Because i have navigation controller on the ViewController so this doesnt disable the swipe on the view. But when i declare like this it work fine but dont know the direction of the swipe.

UIPanGestureRecognizer *noRightShiftForVolume = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)];
    [self.circleProgressBar addGestureRecognizer:noRightShiftForVolume];

The implemenation of the function is like this:

- (void)handleVolumeViewSwipe1:(UISwipeGestureRecognizer *)sender
{

    if (sender.state == UIGestureRecognizerStateBegan) {
        [applicationControllerShared() enableSwipe:NO];
        NSLog(@"good karens");

        if(UISwipeGestureRecognizerDirectionLeft){
        CATransition *animation = [CATransition animation];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
        [animation setDuration:0.50];
        [animation setTimingFunction:
         [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [_circleProgressBar.layer addAnimation:animation forKey:kCATransition];
        NSLog(@"Swipe Left");
        }

        if(UISwipeGestureRecognizerDirectionRight){
            NSLog(@"Swipe Right");
        }
    }

    if (sender.state == UIGestureRecognizerStateEnded)
    {
        [applicationControllerShared() enableSwipe:YES];
        NSLog(@"good karens 110");
    }
}

In the navigation controller BOOL eliminateSwipe; eliminateSwipe function look like this:

-(void) enableSwipe: (BOOL) state
{
    eliminateSwipe = !state;
}

enable swipe function disables the navigation controller swipe and gives me power to implement the function handleVolumeViewSwipe1. I have circle progress bar which i want to detect left and right swipe and perform function according. Any clue how can i done that.

I have tried to implement this SwipeGestureRecognizerDirection in ViewDidLoad and ViewDidAppear but not working for me because of swipe feature of navigation controller.

This is solved with the help of UIPanGestureRecognizer and swipe can be detected with the following code

  if (sender.state == UIGestureRecognizerStateBegan) {
        [applicationControllerShared() enableSwipe:NO];
        CGPoint velocity = [sender velocityInView:_circleProgressBar];

        if(velocity.x < 0)
        {
          NSLOG(@"swipe left");
}else{
 NSLOG(@"swipe right");}
}
1
Have you set noRightShiftForVolume.direction property of gesture ? - CodeChanger
Yes but doesnt help at all. Swipe take me to navigation controller - Jatoi 123
Ok so it will popout from that viewController right ? - CodeChanger
Yes exactly right. - Jatoi 123
Do you realise if(UISwipeGestureRecognizerDirectionLeft){ isn't comparing anything? And you will need a separate UISwipeGestureRecognizer for each direction. - James P

1 Answers

0
votes

As per my exprience you need to apply delegate of UINavigationControllerDelegate to stop popGesture.

Step 1 : Confirm Protocol in .h file. (Optional Step)

@interface ViewController : UIViewController<UINavigationControllerDelegate>

Step 2 : Set delegate in viewDidLoad. (Optional Step)

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

Step 3 : And disable gesture in viewWillDisApper in previos VC. (Required Step)

self.navigationController.interactivePopGestureRecognizer.enabled = YES;

Hope this will helps you.