Saturday 26 May 2012

UISwipeGestureRecognizer swipe multiple views in iphone sdk

- (void)viewDidLoad
{
    [super viewDidLoad];
    appDel = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    appDel.IsCenter = TRUE;
    firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
   
   
    UISwipeGestureRecognizer *leftSwipe  =  [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe:)];
    [leftSwipe setDirection:(UISwipeGestureRecognizerDirectionUp)];
    leftSwipe.delegate  =   self;
    [self.view addGestureRecognizer:leftSwipe];
    [leftSwipe release];
   
    UISwipeGestureRecognizer *rightSwipe  =  [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe:)];
    [rightSwipe setDirection:(UISwipeGestureRecognizerDirectionDown)];
    rightSwipe.delegate   =   self;
    [self.view addGestureRecognizer:rightSwipe];
    [rightSwipe release];


    // Do any additional setup after loading the view, typically from a nib.
}
- (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer
{
           if (appDel.IsCenter == TRUE) {
               CATransition *transition = [CATransition animation];
               transition.duration = 0.75;
               transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
               transition.type = kCATransitionPush;
               transition.subtype =kCATransitionFromTop;
               transition.delegate = self;
               [self.view.layer addAnimation:transition forKey:nil];
             [self.view addSubview:firstView.view];
            appDel.IsCenter = FALSE;
        }
        else {
            [secondView.view removeFromSuperview];
            appDel.IsCenter = TRUE;
        }
  
}
- (void)rightSwipe:(UISwipeGestureRecognizer *)recognizer
{
        if (appDel.IsCenter == TRUE) {
            CATransition *transition = [CATransition animation];
            transition.duration = 0.75;
            transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            transition.type = kCATransitionPush;
            transition.subtype =kCATransitionFromBottom;
            transition.delegate = self;
           
            [self.view.layer addAnimation:transition forKey:nil];
           
             [self.view addSubview:secondView.view];
            appDel.IsCenter = FALSE;
        }
        else {
            [firstView.view removeFromSuperview];
            appDel.IsCenter = TRUE;
      
    }
}
My Facebook

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Nice1
    very halpful
    thank you very much bro.

    ReplyDelete
  3. Replies
    1. IsCenter is boolean. that is check that current view is in center or not.

      Delete
    2. Do you have the tutorial for this?It will be helpful to me

      Delete
    3. Can you please explain me what you want. So I will give you the solution or tutorial.

      Delete