iOS POP动画实践

前言: 没午睡好困 囧~
用途: 可以做提示窗, 也在很多直播的App中比较常见.
我已经封装好-示例下载已经放到我的GitHub, 可下载-了解更多

精心制作, 图片是不是很美

创建继承于UIView的XTPopingView 暂时没做更多功能, 可以实现 下-下 上-下 两种 来看看如何实现吧

声明: 使用Facebook POP了.

1.初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
         self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        [self addSubview:self.flyView];
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClickAction)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}
- (UIView *)flyView
{
    if (!_flyView) {
        _flyView = [[UIView alloc] init];
    }
    return _flyView;
}
2. 开始视图
- (void)startFly:(FlyType)type
{
    switch (type) {
        case FlyTypeUToD:
        {
            _flyView.frame = CGRectMake(SCREEN_WIDTH_XT / 2 - self.fly_w / 2, -self.fly_h, self.fly_w, self.fly_h);
        }
            break;
        case FlyTypeDToD:
        {
            _flyView.frame = CGRectMake(SCREEN_WIDTH_XT / 2 - self.fly_w / 2, SCREEN_HEIGHT_XT + self.fly_h, self.fly_w, self.fly_h);
        }
        default:
            break;
    }
    _flyView.backgroundColor = [UIColor purpleColor];
    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
    anim.toValue = [NSValue valueWithCGPoint:self.center];
    // 速度
    anim.springSpeed = 5;
    // 弹力--晃动的幅度 (springSpeed速度)
    anim.springBounciness = 10.0f;
    [_flyView pop_addAnimation:anim forKey:@"animationShow"];
}
3. 移除视图
- (void)tapClickAction
{
    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(self.center.x, SCREEN_HEIGHT_XT + self.fly_h)];
    [_flyView pop_addAnimation:anim forKey:@"animationRemove"];
    anim.springSpeed = 5;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeFromSuperview];
    });
}

走心文章, 值得点赞 ---文/夏天然后
微博-点我@夏天是个大人了 || QQQ: 498143780

你可能感兴趣的:(iOS POP动画实践)