为了实现某些提示框更好警示的作用,需要加入抖动的效果。 具体做法:抖动就是先变大再变小,最后恢复原样的涡阳,再通过关键帧动画,定义每一段动画的效果和经历时间,即可实现对应效果。
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];复制代码
效果图如下:
#####结束语 如有对本文有任何疑问或者写的不好的地方,请直接留言,我会及时解答和修正,谢谢支持。