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");}
}
noRightShiftForVolume.directionproperty of gesture ? - CodeChangerif(UISwipeGestureRecognizerDirectionLeft){isn't comparing anything? And you will need a separateUISwipeGestureRecognizerfor each direction. - James P