Search code examples
iphoneiosobjective-cuigesturerecognizeruiswipegesturerecognizer

swipe view using UISwipeGestureRecognizer


hi all freind i want ask somthing, i try use label to swipe between views but i cant know the problem?

UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];


-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender{
      ThirdQPage* y=[[ThirdQPage alloc]init];
[self.view.superview addSubview:[y view]];
[self.view removeFromSuperview];}

Solution

  • You could do this -

    - (void)hideView:(NSTimer *)timer
    {    
        UIView *currentView = (UIView *)[timer userInfo];
        [currentView addSubview:self.yourNewView];
        return;
    }
    
    -(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
    {
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                               forView:yourCurrentView cache:YES];
    
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1];
        [NSTimer scheduledTimerWithTimeInterval:0.5 
                                         target:self 
                                       selector:@selector(hideView:) 
                                       userInfo:yourCurrentView 
                                        repeats:NO];
        [UIView commitAnimations];
    }
    

    You can use the same logic to swipe back from your newView to oldView.