刷礼物

#pragma mark - lazyload
- (SVGAPlayer *)player {
    if (!_player) {
        _player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, KNavBarH, KScreenWidth, KScreenHeight - 2*KNavBarH)]; //有些动画太上面,有些动画太下面,折中
        _player.loops = 1;
        _player.clearsAfterStop = YES;
        _player.userInteractionEnabled = NO; //点击可穿透
        _player.delegate = self;
        _player.fillMode = @"Forward";
        _player.contentMode = UIViewContentModeScaleAspectFit;
        _player.backgroundColor = [UIColor clearColor];
    }
    return _player;
}

#pragma mark - SVGAPlayerDelegate
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
    [self.player removeFromSuperview];
}

- (void)sendGift:(GiftModel *)model count:(NSInteger)count {
    //判断金币,调用接口成功
    
    //发送svga礼物
    [UIApplication.sharedApplication.keyWindow addSubview:self.player];

    SVGAParser *parser = [[SVGAParser alloc] init];
    [parser parseWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:model.giftLink ofType:nil]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
       self.player.videoItem = videoItem;
    [self.player startAnimation];
  } failureBlock:nil];

  //发送消息
//    [self sendMessage:model count:count];
}

- (void)initListener {
    [super initListener];
    
    //监听键盘弹出收起
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification {
    //添加回去
    [UIApplication.sharedApplication.keyWindow addSubview:self.player];
}

- (void)keyboardWillShow:(NSNotification *)notification {
    for (UIView *window in [UIApplication sharedApplication].windows) {
        if ([window isKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")]) {
            //视图有且只有一个父视图. 如果视图已经有一个父视图并且这个父视图不是将要添加的视图, 本方法会把视图原有的父视图移除, 将新视图设置为父视图.
            [window addSubview:self.player];
            break;
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容