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

 


//图片进行自动旋转

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

    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"7"]];

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

    [self.view addSubview:imageView];

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

    animation.delegate = self;

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

    //执行时间

    animation.duration = 30;

    animation.cumulative = YES;//累积的

    //执行次数

    animation.repeatCount = INT_MAX;

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

    [imageView.layer addAnimation: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

{

    [super viewDidLoad];


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

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

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

    button12.backgroundColor = [UIColor redColor];

    [self.view addSubview: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

{

    //开始动画

    [UIView beginAnimations:@"testanimation" context:nil];

    [UIView setAnimationDuration:0.5];

    //代理

    [UIView setAnimationDelegate:self];

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

    [UIView setAnimationDidStopSelector:@selector(animationstop)];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //获得视图的位置

    CGRect frames = self.view_1.frame;

    frames.origin.x = 160;

    self.view_1.frame = frames;

    [UIView commitAnimations];

}


-(void)animationstop

{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:0.5];

    CGRect frames = self.view_1.frame;

    frames.origin.x = 0;

    self.view_1.frame = frames;

    [UIView commitAnimations];

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值