/// 開始旋轉(zhuǎn)動(dòng)畫,效果:Y軸360度旋轉(zhuǎn)后停留2秒再繼續(xù)旋轉(zhuǎn)
- (void) startRotationAnimation {
? ? // 添加旋轉(zhuǎn)動(dòng)畫
? ? CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
? ? rotationAnimation.fromValue= [NSNumber numberWithFloat:0];
? ? rotationAnimation.toValue= [NSNumber numberWithFloat:M_PI*2];
? ? rotationAnimation.duration=1.5;// 旋轉(zhuǎn)動(dòng)畫1.5秒完成
? ? rotationAnimation.repeatCount=1;
? ? // 創(chuàng)建動(dòng)畫組
? ? CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
? ? animationGroup.animations=@[rotationAnimation];
? ? animationGroup.duration = 3.5; //間隔2秒后再次開始旋轉(zhuǎn)動(dòng)畫
? ? animationGroup.repeatCount=HUGE_VALF;
? ? [self.layer removeAnimationForKey:@"RotationAnimation"];
? ? [self.layer addAnimation:animationGroup forKey:@"RotationAnimation"];
}
/// 縮放動(dòng)畫,效果:1-1.2倍循環(huán)縮放
- (void) startScaleAnimation {
? ? // 縮放動(dòng)畫
? ? CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
? ? scaleAnimation.fromValue= [NSNumber numberWithFloat:1.0];
? ? scaleAnimation.toValue= [NSNumber numberWithFloat:1.2];
? ? scaleAnimation.duration=0.4;
? ? scaleAnimation.autoreverses=YES;
? ? scaleAnimation.repeatCount=HUGE_VALF;
? ? // 創(chuàng)建動(dòng)畫組
? ? CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
? ? animationGroup.animations=@[scaleAnimation];
? ? animationGroup.duration=0.8;
? ? animationGroup.repeatCount=HUGE_VALF;
? ? [self.layer removeAnimationForKey:@"ScaleAnimation"];
? ? [self.layer addAnimation:animationGroup forKey:@"ScaleAnimation"];
}
/// 晃動(dòng)效果動(dòng)畫
- (void) startShakeAnimation{
? ? // 晃動(dòng)動(dòng)畫
? ? CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
? ? shakeAnimation.values=@[@(-0.3),@(0.3),@(-0.3)];// 晃動(dòng)角度
? ? shakeAnimation.keyTimes=@[@(0),@(0.5),@(1)];// 晃動(dòng)時(shí)機(jī)
? ? shakeAnimation.autoreverses=YES;
? ? shakeAnimation.duration=0.5;
? ? // 創(chuàng)建動(dòng)畫組
? ? CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
? ? animationGroup.animations=@[shakeAnimation];
? ? animationGroup.duration=2.0;
? ? animationGroup.repeatCount=HUGE_VALF;
? ? [self.layer removeAnimationForKey:@"ScaleAnimation"];
? ? [self.layer addAnimation:animationGroup forKey:@"ScaleAnimation"];
}
/// 添加白光閃過動(dòng)畫
- (void) startWhiteLightAnimation{
? ? for(CALayer*layer?in?self.layer.sublayers){
? ? ? ? if([layer.name isEqualToString:@"whiteLightLayer"]){
? ? ? ? ? ? [layer removeFromSuperlayer];
? ? ? ? ? ? break;
? ? ? ? }
? ? }
? ? CALayer*whiteLightLayer = [CALayer layer];
? ? whiteLightLayer.backgroundColor= [[UIColor whiteColor] colorWithAlphaComponent:0.7].CGColor;
? ? whiteLightLayer.frame=CGRectMake(5,0,self.frame.size.width-10,3);
? ? whiteLightLayer.opacity=0.0;
? ? whiteLightLayer.name=@"whiteLightLayer";
? ? [self.layer addSublayer:whiteLightLayer];
? ? // 創(chuàng)建一個(gè) CATransform3D 對(duì)象來設(shè)置傾斜的角度
? ? CATransform3D transform = CATransform3DIdentity;
? ? transform =CATransform3DRotate(transform, -M_PI_4,0.0,0.0,1.0);
? ? whiteLightLayer.transform= transform;
? ? // 改變位置動(dòng)畫
? ? CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
? ? positionAnimation.fromValue= [NSValue valueWithCGPoint:CGPointMake(0,0)];
? ? positionAnimation.toValue= [NSValue valueWithCGPoint:CGPointMake(self.frame.size.width,self.frame.size.height)];
? ? positionAnimation.duration=0.5;
? ? positionAnimation.autoreverses=YES;
? ? // 改變透明度動(dòng)畫
? ? CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
? ? opacityAnimation.fromValue=@(1.0);
? ? opacityAnimation.toValue=@(0.0);
? ? opacityAnimation.duration=0.5;
? ? CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
? ? animationGroup.animations=@[opacityAnimation, positionAnimation];
? ? animationGroup.duration=1.5;// 持續(xù)時(shí)間
? ? animationGroup.repeatCount=HUGE_VALF;
? ? [whiteLightLayer addAnimation:animationGroup forKey:@"WhiteLightAnimation"];
}