ios中的各中动画(旋转,平移)

来源:互联网 发布:uml 数据库建模 编辑:程序博客网 时间:2024/05/30 05:01

 


//图片进行自动旋转

CABasicAnimation是一个最多只能有两个关键帧的动画,

    UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"7"]];

    imageView.frame =CGRectMake(40, 60,200, 250);

    [self.viewaddSubview:imageView];

    CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"transform"];

    animation.delegate =self;

    animation.toValue = [NSValuevalueWithCATransform3D:CATransform3DMakeRotation(M_PI,0, 0,1.0)];

    //执行时间

    animation.duration =30;

    animation.cumulative =YES;//累积的

    //执行次数

    animation.repeatCount = INT_MAX;

    animation.autoreverses=YES;//是否自动重复

    [imageView.layeraddAnimation:animation forKey:@"animation"];


通过CATransition实现类似UINavigationController的pushview及Popview效果

CATransition动画使用了类型type和子类型subtype两个概念。type属性指定了过渡的种类(淡化、推挤、揭开、覆盖)。subtype设置了过渡的方向(从上、下、左、右)。另外,CATransition私有的动画类型有(立方体、吸收、翻转、波纹、翻页、反翻页、镜头开、镜头关)。


/* CATransition *myT = [ CATransition animation];

myT.timingFunction = UIViewAnimationCurveEaseInOut;

myT.type = @"cube";

    //动画类型

    // 1 kCATransitionFromBottom

    // 2 kCATransitionFromLeft

    // 3 kCATransitionFromTop

    // 4 kCATransitionFromRight

//myT.subtype = kCATransitionFromLeft;

    myT.subtype = kCATransitionFromLeft;

myT.duration = 0.5;

[self.navigationController.view.layer addAnimation: myT forKey:nil];

    NSLog(@"app");*/


创建UIView动画(块)——(指过渡效果的动画)


 //方法一:

    //过度动画的效果,是2View的切换

- (void)viewDidLoad

{

    [superviewDidLoad];


    UIButton* button12 = [[UIButtonalloc]initWithFrame:CGRectMake(20,340, 150, 30)];

    [button12 addTarget:self action:@selector(button22)forControlEvents:UIControlEventTouchUpInside];

    [button12 setTitle:@"开始动画" forState:UIControlStateNormal];

    button12.backgroundColor = [UIColorredColor];

    [self.viewaddSubview:button12];

    //方法二:

    // 2 block语法实现

   /* [UIView animateWithDuration:0.5 animations:^{

        CGRect frames = self.view_1.frame;

        frames.origin.x = 160;

        self.view_1.frame = frames;

        //缩放

        self.view_1.transform = CGAffineTransformScale(self.view_1.transform, 0.01, 0.01);

    }completion:^(BOOL finished) {

        CGRect frames = self.view_1.frame;

        frames.origin.x = 0;

        self.view_1.frame = frames;

        //恢复到原始的缩放

        self.view_1.transform = CGAffineTransformIdentity;

    }];*/

}


-(void)button22

{

    //开始动画

    [UIViewbeginAnimations:@"testanimation"context:nil];

    [UIViewsetAnimationDuration:0.5];

    //代理

    [UIViewsetAnimationDelegate:self];

    //动画的响应事件,使视图自动回到原来的位置

    [UIViewsetAnimationDidStopSelector:@selector(animationstop)];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

    //获得视图的位置

    CGRect frames =self.view_1.frame;

    frames.origin.x =160;

    self.view_1.frame = frames;

    [UIViewcommitAnimations];

}


-(void)animationstop

{

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:0.5];

    CGRect frames =self.view_1.frame;

    frames.origin.x =0;

    self.view_1.frame = frames;

    [UIViewcommitAnimations];

}




0 0
原创粉丝点击