Adding swipe gesture recognizer to DetailViewContoller
you should set the direction for the swipe in order to add the right swipe
UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)]; [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; [self.view addGestureRecognizer:gestureRecognizer];
and your swipe handler might look like
-(void)swipeHandler:(UISwipeGestureRecognizer *)recognizer { NSLog(@"Swipe received.");}
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognizer:)]; recognizer.direction = UISwipeGestureRecognizerDirectionRight; recognizer.delegate = self; [self.view addGestureRecognizer:recognizer];}- (void)swipeRecognizer:(UISwipeGestureRecognizer *)sender { if (sender.direction == UISwipeGestureRecognizerDirectionRight){ [UIView animateWithDuration:0.3 animations:^{ CGPoint Position = CGPointMake(self.view.frame.origin.x + 100.0, self.view.frame.origin.y); self.view.frame = CGRectMake(Position.x , Position.y , self.view.frame.size.width, self.view.frame.size.height); [self.navigationController popViewControllerAnimated:YES]; }]; }}
Try This
//Right Swipe
UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)];[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];[self.view addGestureRecognizer:gestureRecognizer];
//Left Swipe
UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)];[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];[self.view addGestureRecognizer:gestureRecognizer];
call method
-(void)swipeHandlerRight:(id)sender{ //Your ViewController}-(void)swipeHandlerLeft:(id)sender{ //Your ViewController}