_lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
? ? _lable.text = @"果然小行家";
? ? _lable.textAlignment = 1;
? ? _lable.center = self.view.center;
? ? _lable.textColor = [UIColor redColor];
? ? _lable.layer.cornerRadius = 50;
? ? _lable.layer.backgroundColor = [UIColor cyanColor].CGColor;
? ? [self.view addSubview:_lable];
//? ? UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//? ? button.frame = CGRectMake(100, 100, 60, 40);
//? ? [button setTitle:@"暫停" forState:0];//實現(xiàn)動畫的暫停
//? ? [button setTitleColor:[UIColor redColor] forState:0];
//? ? [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
//? ? [self.view addSubview:button];
//
//? ? UIButton *resumeButton = [UIButton buttonWithType:UIButtonTypeCustom];
//? ? [resumeButton setTitle:@"重啟" forState:0];
//? ? [resumeButton setTitleColor:[UIColor blueColor] forState:0];
//? ? resumeButton.frame = CGRectMake(200, 100, 60, 40);
//? ? [resumeButton addTarget:self action:@selector(handleResumeBtn:) forControlEvents:UIControlEventTouchUpInside];
//? ? [self.view addSubview:resumeButton];
?一 ? //通過定時器實現(xiàn)旋轉(zhuǎn)------------旋轉(zhuǎn)
//? ? _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(actionTimer:) userInfo:nil repeats:YES];
//? ? [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
//? ? [_timer fire];
二 ? ?//實現(xiàn)位置的移動
//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"transform"];
//? ? CATransform3D form = CATransform3DMakeTranslation(-350, -100, 0);//控制位置
//? ? animal.toValue = [NSValue valueWithCATransform3D:form];
//? ? animal.duration = 1;
//? ? animal.removedOnCompletion = NO;
//? ? animal.fillMode = kCAFillModeForwards;
//? ? [_lable.layer addAnimation:animal forKey:nil];
三 ? ?//大小? 實現(xiàn)大小的變化
//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"transform"];
//? ? CATransform3D form = CATransform3DMakeScale(1.2, 1.2, 1);
//? ? animal.toValue = [NSValue valueWithCATransform3D:form];
//? ? animal.duration = 0.5;
//? ? animal.repeatCount = MAXFLOAT;
//? ? animal.autoreverses = YES;
//? ? [_lable.layer addAnimation:animal forKey:nil];
四 ? ?//實現(xiàn)大小、位置的變化通過bounds缀雳、position來實現(xiàn)
? /*
? ? //bounds
//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"bounds"];
//? ? animal.duration = 2;
//? ? animal.toValue = [NSValue valueWithCGRect:CGRectMake(-200, 0, 10, 10)];
//? ? [_lable.layer addAnimation:animal forKey:nil];
五 ? ? //position
//? ? CABasicAnimation *animal = [CABasicAnimation animationWithKeyPath:@"position"];
//? ? animal.toValue = [NSValue valueWithCGPoint:CGPointMake(250, 500)];
//? ? //取消反彈
//? ? animal.removedOnCompletion = NO;
//? ? animal.duration = 1.5;
//? ? animal.repeatCount = 3;
//? ? animal.fillMode = kCAFillModeForwards;
//? ? [_lable.layer addAnimation:animal forKey:nil];
? ? */
? ? 六 ? ? ? ? ? ? ? ?/****** CAKeyframeAnimation--->關(guān)鍵幀動畫 ****/
? ? //多步動畫? 來回晃動的動畫效果
//? ? CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
//? ? animation.values = @[@0, @50, @-10, @50, @0];
//? ? //設(shè)置每一幀執(zhí)行的時間長短 這個的取值為0-1虫蝶,代表占用時間的比例
//? ? animation.keyTimes = @[@0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1];
//? ? animation.duration = 1;
////? ? animation.repeatCount = 10;
//? ? animation.repeatCount = 10000;
//? ? //設(shè)置幀的中間值如何計算
//? ? animation.calculationMode = kCAAnimationPaced;
//? ? //additive 這個屬性確定動畫執(zhí)行的狀態(tài)是否疊加在控件的原狀態(tài)上
//? ? //默認設(shè)置為NO娇哆,如果我們執(zhí)行兩次位置移動的動畫,會從同一位置執(zhí)行兩次
//? ? //如果設(shè)置為YES,則會在第一次執(zhí)行的基礎(chǔ)上執(zhí)行第二次動畫
//? ? animation.additive = YES;
//? ? [_lable.layer addAnimation:animation forKey:nil];
//? ? _lable.layer.zPosition = 1;
七 ? ?//位置
? ? //沿貝塞爾曲線的動畫
? ? //這個方法將創(chuàng)建橢圓形路徑
? ? //? ? ? ? ? ? ? 實現(xiàn)一個控件圍繞一個點轉(zhuǎn)圈的效果
//? ? CGRect boundingRect = CGRectMake(-40, 0, 100, 100);
//? ? UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:boundingRect cornerRadius:50];
//
//? ? CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//? ? //設(shè)置一個路徑
//? ? animation.path = path.CGPath;
//? ? animation.duration = 4;
//? ? animation.additive = YES;
//? ? animation.repeatCount = HUGE_VALF;
//? ? animation.calculationMode = kCAAnimationPaced;
//? ? animation.rotationMode = kCAAnimationRotateAuto;
//? ? [_lable.layer addAnimation:animation forKey:nil];
八 ? ? ? ? ? ?/********* CASpringAnimation---> 彈性動畫 ********/
//? ? CASpringAnimation *animation = [CASpringAnimation animationWithKeyPath:@"position"];
//? ? animation.toValue = [NSValue valueWithCGPoint:CGPointMake(175, 400)];
//
//? ? //質(zhì)量,影響圖層運動時的彈簧慣性倒信,質(zhì)量越大科贬,彈簧拉伸和壓縮的幅度越大
//? ? //如果把質(zhì)量改成10泳梆,則動畫的速度變慢,并且波動幅度變大
//? ? animation.mass = 3;
//
//? ? //阻尼系數(shù)榜掌,阻止彈簧伸縮的系數(shù)优妙,阻尼系數(shù)越大,停止越快
//? ? animation.damping = 30;
//? ? //初始速率憎账,動畫視圖的初始速度大小
//? ? animation.initialVelocity = 10;
//? ? //剛度? 剛度系數(shù)越大套硼,形變產(chǎn)生的力就越大,運動越快
//? ? animation.stiffness = 10;
//
//? ? animation.duration = 2;
//? ? animation.fillMode = kCAFillModeForwards;
//? ? animation.removedOnCompletion = NO;
//? ? [_lable.layer addAnimation:animation forKey:nil];
? ? 九 ? ? ? ?/**** CATransition--->轉(zhuǎn)場動畫 *****/
//? ? //定義個轉(zhuǎn)場動畫
? ? CATransition *animation = [CATransition animation];
? ? //轉(zhuǎn)場動畫持續(xù)時間
? ? animation.duration = 1;
? ? //轉(zhuǎn)場動畫類型
? ? animation.type = kCATransitionPush;
? ? //轉(zhuǎn)場動畫將去的方向
? ? animation.subtype = kCATransitionFromBottom;
? ? //添加動畫 (轉(zhuǎn)場動畫是添加在層上的動畫)
? ? [_lable.layer addAnimation:animation forKey:nil];