{"id":13697032,"url":"https://github.com/Jonhory/LiveSendGift","last_synced_at":"2025-05-03T17:32:59.760Z","repository":{"id":179114884,"uuid":"73524963","full_name":"Jonhory/LiveSendGift","owner":"Jonhory","description":"直播发送弹幕效果","archived":false,"fork":false,"pushed_at":"2022-11-25T03:29:35.000Z","size":2988,"stargazers_count":358,"open_issues_count":1,"forks_count":73,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-03T18:21:42.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jonhory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-11-12T01:47:24.000Z","updated_at":"2024-06-21T09:47:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1e61c06-5499-42a1-80fd-eeb56d77e5b4","html_url":"https://github.com/Jonhory/LiveSendGift","commit_stats":null,"previous_names":["jonhory/livesendgift"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jonhory%2FLiveSendGift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jonhory%2FLiveSendGift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jonhory%2FLiveSendGift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jonhory%2FLiveSendGift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jonhory","download_url":"https://codeload.github.com/Jonhory/LiveSendGift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224369848,"owners_count":17299961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:51.873Z","updated_at":"2024-11-13T00:31:20.976Z","avatar_url":"https://github.com/Jonhory.png","language":"Objective-C","funding_links":[],"categories":["UI Effects"],"sub_categories":[],"readme":"![](http://ww1.sinaimg.cn/large/c6a1cfeagy1ffbh46t93nj20ky0dsq3x.jpg)\n\n## 感谢\n* 得益于某位不愿留名的同学的帮助，队列模式已经较好的实现了。\n* 感谢[gxtai](https://github.com/gxtai)发现并解决[内存释放](https://github.com/Jonhory/LiveSendGift/issues/20)问题\n\n## 重要信息\n* 2017年09月25日18:42:00 修复了在iOS11下必现`EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)`的崩溃BUG。\n* 已知bug提示：在替换模式`LiveGiftAddModeReplace`下使用`animatedWithGiftModel`方法将导致UI效果不理想的bug。建议是`animatedWithGiftModel`方法使用于`LiveGiftAddModeAdd`模式。\n* 2017年12月25日11:39:39 修复在iOS11下可能出现的`.cxx destruct`崩溃问题。\n* 2021年3月23日确认了`for`循环添加礼物时会出现后续[礼物`toNumber`变大](https://github.com/Jonhory/LiveSendGift/issues/19)的问题。\u003cdel\u003e已提交修复代码，待开发者确认是否完全修复。\u003c/del\u003e\n* 2021年7月12日确认并解决了[内存释放](https://github.com/Jonhory/LiveSendGift/issues/20)问题。\n* 2022年11月25日确认并修复了[`addLiveGiftShowModel:showNumber:`显示异常](https://github.com/Jonhory/LiveSendGift/issues/21)问题。\n\t\n\t### 请使用2021/03/25之前的代码的开发者注意\n\n\t以下代码需调整\n\t\n\t```\n\tif ([oldKey isEqualToString:key]) {\n\t\toldNumber = oldModel.toNumber;\n\t\tshowModel.toNumber += oldNumber;\n\t\t[self.waitQueueArr removeObject:oldModel];\n\t\tbreak;\n\t}\n\t```\n\n\t修改为：\n\t\n\t```\n\tif ([oldKey isEqualToString:key] \u0026\u0026 oldModel.animatedTimer == nil) {\n\t\toldNumber = oldModel.toNumber;\n\t\tshowModel.toNumber += oldNumber;\n\t\t[self.waitQueueArr removeObject:oldModel];\n\t\tbreak;\n\t}\n\t```\n\n## 导航\n* [目标](#目标)\n* [版本更新说明](#版本更新说明)\n* [最新版本](#最新版本)\n* [快速使用](#快速使用)\n* [自定义配置](#自定义配置)\n\n## \u003ca id=\"目标\"\u003e\u003c/a\u003e目标:\n\n* 弹幕过几秒自动消失\n* 实现A用户弹幕出现时，B用户发送礼物，B用户弹幕在A用户弹幕下方,A/B用户弹幕存在时，A/B用户连续发送礼物，弹幕显示的礼物数量增加，谁的礼物数量较大，谁的弹幕在上方。\n* A/B用户弹幕存在时，C用户发送礼物，A/B用户中较早出现的弹幕被替换成C用户的弹幕数据，并且C用户的弹幕处于下方\n\n### \u003ca id=\"版本更新说明\"\u003e\u003c/a\u003e版本更新:\n\n#### V1.0\n* 大致实现了不同用户增加弹幕的效果\n\n#### V1.1\n* 实现了用户连续发送数字增加效果\n* 实现了新增弹幕从空位出现的效果\n\n#### V1.2\n* 实现了第二个用户之后送礼物替换较早的弹幕效果(完善)\n\n#### V1.3\n* 实现了上面的视图移除后，正在连击的下面的视图移动到上面的效果\n\n#### V1.4\n* 实现了目标效果😊😊😊\n\n#### V1.5\n* 实现了自定义最大礼物数量的需求\n\n#### V1.6\n* 新增了自下而上的展现效果\n\n#### V1.7\n* 解决了一个视图显示BUG，现在几乎不会出现该BUG。\n\n#### V1.8\n* 支持向左移除弹幕，支持左边出现动画效果，增加弹幕移除后的回调代理。\n\n#### \u003ca id=\"最新版本\"\u003e\u003c/a\u003e V1.901测试版\n* 支持从1增加到某个数字的动画（在替换模式`LiveGiftAddModeReplace`下存在小bug，如果有某猿能提供帮助将不胜感激）\n* 支持队列模式（如下GIF图，注意看鼠标～）\n* 移除的模式增加无动画移除\n* 修改了部分枚举名称更符合OC语法\n* 暴露了动画时长属性，方便开发者依据不同情况自行修改\n\n![](https://ws1.sinaimg.cn/large/c6a1cfeagy1fjq279e03tg20a30iek2l.gif)\n\n### \u003ca id=\"快速使用\"\u003e\u003c/a\u003e快速使用\n* 使用的第三方库:\n  * [Masonry](https://github.com/SnapKit/Masonry)\n  * [SDWebImage](https://github.com/rs/SDWebImage)\n\n* 两个模型:`LiveGiftListModel`和`LiveUserModel`\n  * `LiveGiftListModel `是用来显示弹幕上右侧礼物图片`picUrl`和打赏的语句`rewardMsg`的，礼物有`type`字段\n  * `LiveUserModel `是用来显示送礼物的人的名称`name`和头像`iconUrl`\n  \n* 导入`#import \"LiveGiftShowCustom.h\"`\n\n* `@property (nonatomic ,weak) LiveGiftShowCustom * customGiftShow;\n`\n\n```\n/*\n 礼物视图支持很多配置属性，开发者按需选择。\n */\n- (LiveGiftShowCustom *)customGiftShow{\n    if (!_customGiftShow) {\n        _customGiftShow = [LiveGiftShowCustom addToView:self.view];\n        _customGiftShow.addMode = LiveGiftAddModeAdd;\n        [_customGiftShow setMaxGiftCount:3];\n        [_customGiftShow setShowMode:LiveGiftShowModeFromTopToBottom];\n        [_customGiftShow setAppearModel:LiveGiftAppearModeLeft];\n        [_customGiftShow setHiddenModel:LiveGiftHiddenModeNone];\n        [_customGiftShow enableInterfaceDebug:YES];\n        _customGiftShow.delegate = self;\n    }\n    return _customGiftShow;\n}\n```  \n\n* 在开发中使用\n\n```\nLiveGiftShowModel * listModel = [LiveGiftShowModel giftModel:self.giftArr[3] \n                                                   userModel:self.firstUser];\n[self.giftShow addGiftListModel:listModel];\n```\n即可完成接入。每一次点击只需要`[self.giftShow addGiftListModel:listModel];`即可自动计数加一。最高支持显示9999。\n\n### 特别说明\n\n* 层次结构说明,如下图:\n\n![](https://ws1.sinaimg.cn/large/c6a1cfeagy1ft3d4bi9cwj20zd0alwi2.jpg)\n\n* `LiveGiftShowCustom.m`中\n\n```\n#pragma mark - 初始化\n+ (instancetype)addToView:(UIView *)superView{\n    LiveGiftShowCustom * v = [[LiveGiftShowCustom alloc]init];\n    [superView addSubview:v];\n    //布局\n    [v mas_makeConstraints:^(MASConstraintMaker *make) {\n        //这个改动之后要注意修改LiveGiftShowView.h的kViewWidth\n        make.width.equalTo(@244);\n        //将主视图的高度设置0.01，保证弹幕后面的视图能响应点击事件。\n        make.height.equalTo(@0.01);\n        //这个可以任意修改\n        make.left.equalTo(superView.mas_left);\n        //这个参数在的设定应该注意最大礼物数量时不要超出屏幕边界。\n        make.top.equalTo(superView.mas_top).offset(400);\n    }];\n    v.backgroundColor = [UIColor clearColor];\n    return v;\n}\n```\n\n### \u003ca id=\"自定义配置\"\u003e\u003c/a\u003e自定义配置\n* `LiveGiftShowCustom` 管理所有弹幕的视图\n\n|两个弹幕之间的高度差|两个交换动画时长|\n|:----------------:|:------------:|\n|kGiftViewMargin  |kExchangeAnimationTime|\n|50.0               |0.25         |\n\n* `LiveGiftShowView`一个弹幕的视图\n\n|弹幕背景宽|弹幕背景高|送礼者名称字号|送礼者名称文字颜色|礼物寄语字号|礼物寄语文字颜色|\n|:------:|:------:|:------:|:------:|:------:|:------:|\n|kViewWidth|kViewHeight|kNameLabelFont|kNameLabelTextColor|kGiftLabelFont|kGiftLabelTextColor|\n|240.0|44.0|12.0|whiteColor|10.0|orangeColor|\n\n|每个数字图片宽度|弹幕几秒后消失|数字改变动画时长|弹幕消失动画时长|\n|:------:|:------:|:------:|:------:|\n|kGiftNumberWidth|kTimeOut|kNumberAnimationTime|kRemoveAnimationTime|\n|15.0|3|0.25|0.5|\n\n## \u003ca id=\"关于我\"\u003e\u003c/a\u003e关于我\n * 如果在使用过程中遇到问题，或者想要与我分享／吐槽／建议／意见\u003cjonhory@163.com\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJonhory%2FLiveSendGift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJonhory%2FLiveSendGift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJonhory%2FLiveSendGift/lists"}