#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;
}
}
}
刷礼物
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 前段时间分享了 iOS 动画队列-仿映客刷礼物效果,收到不少同学的建议,大家普遍反映这个动画在项目中是基于 IM ...