毛玻璃效果和簡單的動畫

1.毛玻璃效果 (iOS8之后)?

iOS8之后新加了UIBlurEffect類和UIVisualEffectView類使用起來也很簡單?

UIBlurEffect類設(shè)定毛玻璃效果的類型(3中類型)

UIVisualEffectView類在創(chuàng)建時加入UIBlurEffect的類的對象

2.系統(tǒng)自帶的uiview的block塊

一個簡單的圖片視圖的放大然后漸漸消失的動畫最后移除視圖 可以使用嵌套block塊來實(shí)現(xiàn)

3.CALayer層的動畫

CABasicAnimation一般用法通過fromValue和toValue來指定開始和結(jié)束的值

屬性Autoreverses 當(dāng)設(shè)為YES時,在它到達(dá)目的地后,動畫回到原始的值,代替直接跳轉(zhuǎn)到開始的值

Duration 動畫的時長? repeatCount 動畫的重復(fù)次數(shù)(默認(rèn)為0)只走一次。

Speed 動畫播放按照默認(rèn)的速度播放 默認(rèn)為1.0 如果改變它的值會影響到動畫的持續(xù)時間。

RemovedOnCompletion 設(shè)為YES在指定時間內(nèi)動畫完成后,動畫從層上移除

animationWithKeyPath的值:

transform.scale 縮放?

transform.translation.y 縱向移動

transform.translation.x 橫向移動

opacity 透明度

transform.rotation.z 旋轉(zhuǎn)

backgroundColor 背景色變化


+(CABasicAnimation *)opacityForever_Animation:(float)time //永久閃爍的動畫

{

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

animation.fromValue=[NSNumber numberWithFloat:1.0];

animation.toValue=[NSNumber numberWithFloat:0.0];

animation.autoreverses=YES;

animation.duration=time;

animation.repeatCount=FLT_MAX;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

+(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time; //有閃爍次數(shù)的動畫

{

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

animation.fromValue=[NSNumber numberWithFloat:1.0];

animation.toValue=[NSNumber numberWithFloat:0.4];

animation.repeatCount=repeatTimes;

animation.duration=time;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

animation.autoreverses=YES;

return? animation;

}

+(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x //橫向移動

{

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

animation.toValue=x;

animation.duration=time;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

+(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y //縱向移動

{

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

animation.toValue=y;

animation.duration=time;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

+(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repeatTimes //縮放

{

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

animation.fromValue=orginMultiple;

animation.toValue=Multiple;

animation.duration=time;

animation.autoreverses=YES;

animation.repeatCount=repeatTimes;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

+(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes //組合動畫

{

CAAnimationGroup *animation=[CAAnimationGroup animation];

animation.animations=animationAry;

animation.duration=time;

animation.repeatCount=repeatTimes;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

return animation;

}

+(CAKeyframeAnimation *)keyframeAniamtion:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes //路徑動畫

{

CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];

animation.path=path;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

animation.autoreverses=NO;

animation.duration=time;

animation.repeatCount=repeatTimes;

return animation;

}

CAKeyFrameAnimation 關(guān)鍵幀動畫 values屬性指明整個動畫過程中的關(guān)鍵幀點(diǎn)

path和values作用一樣 指定整個動畫經(jīng)過的路徑 當(dāng)values和path同時指定時,values屬性會被忽略。

keyTimes 指定一個數(shù)組用來為每一個路徑指定動畫時間如果沒有設(shè)置keyTimes,系統(tǒng)默認(rèn)每一個路徑的時間為:time = duration/(values.count - 1),每一個路徑的時間相。如果設(shè)置路徑的動畫時間不一致時可以傳入一個數(shù)組 數(shù)組的首尾為0和1 如 animation.keyTimes = @[[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.2],[NSNumber numberWithFloat:0.4],[NSNumber numberWithFloat:0.8],[NSNumber numberWithFloat:1.0]];那么第一段動畫時長為(0.2-0.0)* duration,第二段為(0.4-0.2)*duration 依次計算動畫時長。

timeFunctions用以指定時間函數(shù),類似與運(yùn)動的加速度

kCAMediaTimingFunctionLinear//線性

?kCAMediaTimingFunctionEaseIn//淡入

?kCAMediaTimingFunctionEaseOut//淡出

?kCAMediaTimingFunctionEaseInEaseOut//淡入淡出

?kCAMediaTimingFunctionDefault//默認(rèn)

calculationMode來決定每一個子路徑運(yùn)動的類型

kCAAnimationLinear//默認(rèn),線性

?kCAAnimationDiscrete//離散,無中間過程,但keyTimes設(shè)置的時間依舊生效,物體跳躍地出現(xiàn)在各個關(guān)鍵幀上

?kCAAnimationPaced//平均,keyTimes跟timeFunctions失效

?kCAAnimationCubic//平均,同上

?kCAAnimationCubicPaced//平均,同上

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容