iOS动画 基本动画操作和长按控件抖动

//

//  ViewController.m

//  070401核心动画

//

//  Created by tianshangrenjian on 15/7/4.

//  Copyright © 2015 tianshangrenjian. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

@property (strong, nonatomic)CALayer *myLayer;

@end


@implementation ViewController


- (void)longPress

{

    NSLog(@"longpress");

    CAKeyframeAnimation *frame=[CAKeyframeAnimation animation];

    CGFloat left=-M_PI_2*0.125;

    CGFloat right=M_PI_2*0.125;

    

    

    frame.keyPath=@"postion";

    frame.keyPath=@"transform.rotation";

    

    frame.values=@[@(left),@(right),@(left)];

    frame.duration=0.1;

    frame.repeatCount=10;

    [self.iconImg.layer addAnimation:frame forKey:nil];

    

    //取消动画

    [self.iconImg.layer removeAnimationForKey:@"transform.rotation"];

    

}



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    self.myLayer=[[CALayer alloc ] init];

    self.myLayer.frame=CGRectMake(0, 0, 40, 40);

    

    self.myLayer.backgroundColor=[UIColor greenColor].CGColor;

    

    

    self.myLayer.anchorPoint=CGPointMake(0, 0);//0----1   停靠点的一个比例

    

    [self.schLayer.layer addSublayer:self.myLayer];

    

    

    

    UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)];

    

    gesture.minimumPressDuration=3;

    

    [self.iconImg addGestureRecognizer:gesture];

    self.iconImg.userInteractionEnabled=YES;

    

    

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)xScaleandRotate

{

    CABasicAnimation *anim=[CABasicAnimation animation];

    anim.keyPath=@"transform";

    

    anim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(2, 2, 3)];

    

    anim.duration=2;

    anim.removedOnCompletion=NO;

    anim.fillMode=kCAFillModeBackwards;

    

    

    CABasicAnimation *rotate=[CABasicAnimation animation];

    rotate.keyPath=@"transform";

    rotate.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 3, 1, 0)];

    rotate.removedOnCompletion=NO;

    rotate.fillMode=kCAFillModeBackwards;

    

    CABasicAnimation *rotate1=[CABasicAnimation animation];

    rotate1.keyPath=@"transform";

    rotate1.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 3, 10, 0)];

    rotate1.removedOnCompletion=NO;

    rotate1.fillMode=kCAFillModeBackwards;

    

    

    CAAnimationGroup *group=[CAAnimationGroup animation];

    

    group.animations=@[anim,rotate,rotate1];

    group.duration=5;

    [self.myLayer addAnimation:group forKey:nil];

    

    


}

//基本动画:平移 旋转   放大缩小

- (void)xxTranslation

{

    CABasicAnimation *anim=[CABasicAnimation animation];

    anim.keyPath=@"transform";

    anim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(100, 100, 30)];

    

    anim.duration=3;

    anim.removedOnCompletion=NO;//不删除动画状态

    anim.fillMode=kCAFillModeForwards;//保持动画状态

    [self.myLayer addAnimation:anim forKey:nil];

}

- (void)traceMove

{

    CAKeyframeAnimation *key=[CAKeyframeAnimation animation];

    NSValue *v1=[NSValue valueWithCGPoint:CGPointMake(0, 0)];

    NSValue *v2=[NSValue valueWithCGPoint:CGPointMake(0, 100)];

    NSValue *v3=[NSValue valueWithCGPoint:CGPointMake(100, 100)];

    NSValue *v4=[NSValue valueWithCGPoint:CGPointMake(100, 0)];

    NSValue *v5=[NSValue valueWithCGPoint:CGPointMake(0, 0)];

    key.keyPath=@"position";

    //    key.values=@[v1,v2,v3,v4];

    key.values=@[v1,v2,v3,v4,v5];

    key.duration=5;

    

    key.autoreverses=YES;

    key.removedOnCompletion=NO;

    key.fillMode=kCAFillModeForwards;

    [self.myLayer addAnimation:key forKey:nil];

    

}

- (void)traceMoveline//沿着线走

{

    CAKeyframeAnimation *key=[CAKeyframeAnimation animation];

    

    CGMutablePathRef path=CGPathCreateMutable();

    

    CGPathAddArc(path, NULL, 100, 100, 50, 0, M_PI_2*2, 0);

    

    key.path=path;

    

    

//    

//    NSValue *v1=[NSValue valueWithCGPoint:CGPointMake(0, 0)];

//    NSValue *v2=[NSValue valueWithCGPoint:CGPointMake(0, 100)];

//    NSValue *v3=[NSValue valueWithCGPoint:CGPointMake(100, 100)];

//    NSValue *v4=[NSValue valueWithCGPoint:CGPointMake(100, 0)];

//    NSValue *v5=[NSValue valueWithCGPoint:CGPointMake(0, 0)];

    key.keyPath=@"position";

//    //    key.values=@[v1,v2,v3,v4];

//    key.values=@[v1,v2,v3,v4,v5];

    key.duration=5;

    

    key.autoreverses=YES;

    key.removedOnCompletion=NO;

    key.fillMode=kCAFillModeForwards;

    [self.myLayer addAnimation:key forKey:nil];

    

}

- (void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event

{

    [self traceMove];

    //[self xxTranslation];

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    

                    

}

@end


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值