如何将uiview从左向右移动,反之亦然 [英] How to move the uiview from left to right and vice versa

查看:118
本文介绍了如何将uiview从左向右移动,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一个应用程序。在那里我为一个视图动画从左到右和从右到左移动并更改该视图中包含的标签的值。但是当我单击左侧时,该视图被删除或右键和新视图覆盖旧视图。所以我不想覆盖。我想添加新视图。我的代码是

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];
             }
         }

我只需在左边的右边按钮调用centerAnimation1方法动作方法。调用这个后,我改变了标签值。

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

推荐答案

试试这个

首先cl到L

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

然后R到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*/}];

这篇关于如何将uiview从左向右移动,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆