為了實現某些提示框更好警示的作用,需要加入抖動的效果。 具體做法:抖動就是先變大再變小,最後恢復原樣的渦陽,再通過關鍵幀動畫,定義每一段動畫的效果和經歷時間,即可實現對應效果。
CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
popAnimation.duration = 0.4;
popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DIdentity]];
popAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f, @1.0f];
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[_mainView.layer addAnimation:popAnimation forKey:nil];
複製程式碼
效果圖如下:
#####結束語 如有對本文有任何疑問或者寫的不好的地方,請直接留言,我會及時解答和修正,謝謝支援。