Swipe Gesture in Segment Unknown 23:23:00 Unknown - (void)viewDidLoad { [super viewDidLoad]; i=0; //Right Swipe UISwipeGestureRecognizer *gestureRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)]; [gestureRightRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; [self.view addGestureRecognizer:gestureRightRecognizer]; //Left Swipe UISwipeGestureRecognizer *gestureLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)]; [gestureLeftRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [self.view addGestureRecognizer:gestureLeftRecognizer]; } -(void)swipeHandlerRight:(id)sender { if (i>0) { i--; [self segmentClick]; } } -(void)swipeHandlerLeft:(id)sender { if (i<=1) { i++; [self segmentClick]; } } - (IBAction)segClciekd:(id)sender { [self segmentClick]; } -(void)segmentClick{ NSLog(@"%d",i); if (i==0) { //} // if (_segment.selectedSegmentIndex==i) { _view1.hidden=NO; _view2.hidden=YES; _view3.hidden=YES; [_segment setSelectedSegmentIndex:0]; // } } else if (i==1) { NSLog(@"%d",i); // if (_segment.selectedSegmentIndex==i) { _view1.hidden=YES; _view2.hidden=NO; _view3.hidden=YES; [_segment setSelectedSegmentIndex:1]; // } } else { _view1.hidden=YES; _view2.hidden=YES; _view3.hidden=NO; [_segment setSelectedSegmentIndex:2]; } } Tweet Share Share Share Share Sign up here with your email
[super viewDidLoad];
i=0;
//Right Swipe
UISwipeGestureRecognizer *gestureRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)];
[gestureRightRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:gestureRightRecognizer];
//Left Swipe
UISwipeGestureRecognizer *gestureLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)];
[gestureLeftRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:gestureLeftRecognizer];
}
-(void)swipeHandlerRight:(id)sender
{
if (i>0) {
i--;
[self segmentClick];
}
}
-(void)swipeHandlerLeft:(id)sender
{
if (i<=1) {
i++;
[self segmentClick];
}
}
- (IBAction)segClciekd:(id)sender {
[self segmentClick];
}
-(void)segmentClick{
NSLog(@"%d",i);
if (i==0) {
//}
// if (_segment.selectedSegmentIndex==i) {
_view1.hidden=NO;
_view2.hidden=YES;
_view3.hidden=YES;
[_segment setSelectedSegmentIndex:0];
// }
}
else if (i==1) {
NSLog(@"%d",i);
// if (_segment.selectedSegmentIndex==i) {
_view1.hidden=YES;
_view2.hidden=NO;
_view3.hidden=YES;
[_segment setSelectedSegmentIndex:1];
// }
}
else {
_view1.hidden=YES;
_view2.hidden=YES;
_view3.hidden=NO;
[_segment setSelectedSegmentIndex:2];
}
}