iOS 动画一

#import "ViewController.h"
#import "QuartzCore/QuartzCore.h"

@interface ViewController ()
{
    UIButton *box  ;
    UIButton *box2  ;
    
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor blackColor];
    
    
    box = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    box.frame= CGRectMake(0,0,50,50);
    [box setTitle:@"hello" forState:UIControlStateApplication];
    //box.titleLabel.text = @"hello";
    
    // box = [[UIView alloc]initWithFrame:CGRectMake(10,10,50,50)];
    box.backgroundColor = [UIColor yellowColor];
    
    
    box2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    box2.frame= CGRectMake(0,0,50,50);
    [box2 setTitle:@"hello" forState:UIControlStateApplication];
    //box.titleLabel.text = @"hello";
    
    // box = [[UIView alloc]initWithFrame:CGRectMake(10,10,50,50)];
    box2.backgroundColor = [UIColor yellowColor];
    
    [self.view addSubview: box];
    [self.view addSubview: box2];
    
    /** 
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.toValue = (id)[UIColor blueColor].CGColor;
    
    animation.duration = 1;
    animation.autoreverses = YES;
    
    [self.view.layer addAnimation:animation forKey:@"backgroundColor"];
    */
    /** 
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    
    animation.values = [NSArray arrayWithObjects:
                       //(id)self.view.backgroundColor,
                        (id)[UIColor  yellowColor].CGColor,
                        (id)[UIColor  greenColor].CGColor,
                        (id)[UIColor  blueColor].CGColor,
                        nil];
    animation.duration = 4;
    animation.autoreverses = YES;
    
    [self.view.layer addAnimation:animation forKey:@"backgroundColor"];
     */
      
 //  [box release];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

 
- (IBAction)go:(UIButton *)sender {
    
   
    
    
}

- (IBAction)animalTest:(UIButton *)sender {
    /**
    [UIView beginAnimations:@"box-animation" context:nil];
    [UIView setAnimationDuration:1];
  
    box.backgroundColor = [UIColor redColor];
    box.frame = CGRectMake(50, 50, 200, 100);
    box.alpha = 0.5;
    
    [UIView commitAnimations];
     */

    /**
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
   // animation.repeatCount=100;
    CGMutablePathRef apath = CGPathCreateMutable();
    
    CGPathMoveToPoint(apath, nil, 20, 20);//move to start point
    
    CGPathAddCurveToPoint(apath, nil, 160, 30, 220, 220, 300, 30);
    
    animation.path =apath;
    animation.duration = 2;
    animation.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
    animation.rotationMode = kCAAnimationRotateAutoReverse;//kCAAnimationRotateAuto;
    //animation.autoreverses = YES;
    
    
    
    
    CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animation];
   // animation2.repeatCount=100;
    
    animation2.path =apath;
    animation2.duration = 2;
    animation2.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
    animation2.rotationMode = kCAAnimationRotateAuto;//kCAAnimationRotateAuto;
    //animation2.autoreverses = YES;
    
    
    [box.layer addAnimation:animation forKey:@"position"];
    [box2.layer addAnimation:animation2 forKey:@"position"];
    
    CFRelease(apath) ;
   */
    //创建Y轴旋转动画
    CABasicAnimation *flip =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    flip.toValue = [NSNumber  numberWithDouble:3.14];
   // flip.autoreverses = YES;
   //缩放动画
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scale.toValue = [NSNumber numberWithDouble:.5];
    scale.duration = 0.5;
 
    scale.autoreverses = YES;
    
    //将缩放动画与反转动画合成
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group .animations = [NSArray arrayWithObjects:flip,scale, nil];
    
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] ;
    
    group.duration = 1;

    
  //  group.autoreverses = YES;
    group.fillMode = kCAFillModeForwards;
   group.removedOnCompletion = NO ;
    [self.view.layer addAnimation:group forKey:@"flip"];
    
    

}
@end

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值