iOS的几个动画效果

iOS的几个动画效果

  1. 粒子发射器
  • CAEmitterLayer 高性能的粒子引擎

  • emitterPosition : 位置

  • emitterSize : 大小

  • emitterMode :发射的模式

  • emitterShape :形状

  • renderMode :粒子如何混合。

  • preservesDepth :把3D粒子系统平面化

  • emitterCells : 添加cell

  • CAEmitterCell 发射的元素

  • contents : 设置图片

  • birthRate : 生成速率

  • lifetime : 生存时间

  • lifetimeRange : 区间

  • velocity : 速度

  • velocityRange :速度区间

  • scale : 放大倍数

  • scaleRange : 区间

  • scaleSpeed : 放大速度

  1. UIBezierPath + CAShapeLayer + mask属性 + path动画
  • 用UIBezierPath生成开始和结束时的path
  • 新建CAShapeLayer并设置显示的path
  • 设置mask属性
  • 用开始和结束的path做path动画
UIBezierPath *start = [UIBezierPath bezierPathWithOvalInRect:sender.frame];
    CGRect rect = CGRectInset(sender.frame, -self.view.frame.size.height, -self.view.frame.size.height);
    UIBezierPath *end = [UIBezierPath bezierPathWithOvalInRect:rect];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = end.CGPath;
    maskLayer.fillMode = kCAFillRuleEvenOdd;
    _anotherView.layer.mask = maskLayer;
​
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.fromValue = (__bridge id)start.CGPath;
    animation.toValue = (__bridge id)end.CGPath;
    animation.duration = 0.5;
    [maskLayer addAnimation:animation forKey:@"path"];
 
  1. Controller转场动画: UIViewControllerAnimatedTransitioning协议 + 快照 + 推力重力
    新建一个类实现UIViewControllerAnimatedTransitioning协议。
- (NSTimeInterval)transitionDuration:(id)transitionContext

- (void)animateTransition:(id)transitionContext

在要做动画的controller实现协议

代码块

- (id)animationControllerForDismissedController:(UIViewController *)dismissed {
    return self.transition;
}

在- (void)animateTransition:(id)transitionContext中做转场动画。

UIView *toV = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
UIView *fromV = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view;
[[transitionContext containerView] addSubview:toV];
[[transitionContext containerView] sendSubviewToBack:toV];
UIView *from = [fromV snapshotViewAfterScreenUpdates:NO];
CGFloat w = fromV.frame.size.width / 20;
CGFloat h = fromV.frame.size.height / 20;
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:[transitionContext containerView]];
NSMutableArray *items = [NSMutableArray array];
for (CGFloat x = 0; x < fromV.frame.size.width; x += w) {
    for (CGFloat y = 0; y < fromV.frame.size.height; y += h) {
        CGRect frame = CGRectMake(x, y, w, h);
        UIView *v = [from resizableSnapshotViewFromRect:frame afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero];
        [[transitionContext containerView] addSubview:v];
        v.frame = frame;
        [items addObject:v];
        UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:@[v] mode:UIPushBehaviorModeInstantaneous];
        push.pushDirection = CGVectorMake([self randomBetween:-0.15 and:0.15], [self randomBetween:-0.15 and:0.15]);
        push.active = YES;
        [_animator addBehavior:push];
    }
}
​
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:items];
[_animator addBehavior:gravity];
[fromV removeFromSuperview];
​
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(complete) userInfo:nil repeats:NO];
self.transitionContext = transitionContext;

你可能感兴趣的:(iOS的几个动画效果)