项目中经常出现版本更新提示框,类似于UIAlertController的复杂提示框等,只需要自定义view,调用如下代码即可
调用方法
- (IBAction)clickInviteFriendsButton:(UIButton *)sender {
_inviteFriendsView.hidden = NO;
[[self class]animationAlert:_inviteFriendsView];
}
自定义动画(Object-C版)
+(void) animationAlert:(UIView *)view{
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.0f, @0.5f, @0.75f, @1.0f];
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:popAnimation forKey:nil];
}
自定义动画(Swift版)
class func animationAlert(view: UIView ){
let popAnimation = CAKeyframeAnimation.init(keyPath: "transform")
popAnimation.duration = 0.4
popAnimation.values = [NSValue.init(caTransform3D: CATransform3DMakeScale(0.01,0.01, 1.0)),
NSValue.init(caTransform3D: CATransform3DMakeScale(1.1, 1.1, 1.0)),
NSValue.init(caTransform3D: CATransform3DMakeScale(0.9, 0.9, 1.0)),
NSValue.init(caTransform3D:CATransform3DIdentity)]
popAnimation.keyTimes = [0.0, 0.5, 0.75, 1.0]
popAnimation.timingFunctions = [CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut),CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut),CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)]
view.layer.cornerRadius = 5
view.layer.masksToBounds = true
view.layer.add(popAnimation, forKey: nil)
}
网友评论