Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the uiview from left to right and vice versa

Tags:

ios

iphone

Hi I am developing one application.In that i did the animation for one view to move from left to right and right to left and changing the values for labels contained in that view.But that view is removed when i click left or right button and new view is overriding the old view.So i don't want to overriding.Just i want to add new view.My code is

    -(void)centerAnimation1:(id)sender
     {
         UIView *currentView = daysview;
            theWindow = daysview;
         // set up an animation for the transition between the views
        CATransition *animation = [CATransition animation];
            animation.delegate = self;
        [animation setDuration:0.4];
        [animation setType:kCATransitionMoveIn];

         if(rhtolft)
         {
             [animation setSubtype:kCATransitionFromLeft];
         }
         else
         {
             [animation setSubtype:kCATransitionFromRight];
         }
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
            [currentView removeFromSuperview];
        }


        - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

             if(animate)
             {
                 CATransition *animation = [CATransition animation];
                 animation.delegate = self;
                 [animation setDuration:0.4];
                 [animation setType:kCATransitionMoveIn];
                 if(rhtolft)
                 {
                     [animation setSubtype:kCATransitionFromLeft];
                     rhtolft=NO;
                 }
                 else
                 {
                     [animation setSubtype:kCATransitionFromRight];                
                 }
                 [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
                 animate=NO;
                 [self.view addSubview:daysview];
             }
         }

Just i call the centerAnimation1 method in left nad right button action method.After calling this one,i changed the label values.

like image 492
venkat Avatar asked May 03 '13 10:05

venkat


1 Answers

try this

First clik L to R

     CGRect basketTopFrame = Yourview.frame;
         basketTopFrame.origin.x = 115;
     [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ Yourview.frame = basketTopFrame; } completion:^(BOOL finished){ }];

then R To L

    CGRect napkinBottomFrame = Yourview.frame;
     napkinBottomFrame.origin.x = 0;
     [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ Yourview.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}];
like image 142
SAMIR RATHOD Avatar answered Oct 01 '22 09:10

SAMIR RATHOD