-
Notifications
You must be signed in to change notification settings - Fork 479
控制层上的按钮如何 添加 删除 修改?
changsanjiang edited this page Sep 29, 2020
·
1 revision
本文均以修改player.defaultEdgeControlLayer
为例, 播放器上的其他控制层的调整与此相同.
控制层上的布局根据区域分为: topAdapter, leftAdapter, bottomAdapter, rightAdapter 及 centerAdapter. 我们将与这些 adapter 进行交互, 调整它们上面的按钮.
在 topAdapter 上添加一个分享按钮
// 为分享按钮提供一个标识tag(tag需要是唯一的, 后续在需要时, 可用于获取该item)
SJEdgeControlButtonItemTag shareItemTag = 10;
// 创建分享按钮
SJEdgeControlButtonItem *shareItem = [SJEdgeControlButtonItem.alloc initWithImage:[UIImage imageNamed:@"icon_share.png"] target:self action:@selector(shareItemWasTapped) tag:shareItemTag];
// 添加到 topAdapter 中
[_player.defaultEdgeControlLayer.topAdapter addItem:shareItem];
[_player.defaultEdgeControlLayer.topAdapter reload];
删除 topAdapter 上的返回按钮
[_player.defaultEdgeControlLayer.topAdapter removeItemForTag:SJEdgeControlLayerTopItem_Back];
[_player.defaultEdgeControlLayer.topAdapter reload];
-
修改点击事件
获取到 topAdapter 上的返回按钮, 并修改按钮的点击事件
SJEdgeControlButtonItem *backItem = [_player.defaultEdgeControlLayer.topAdapter itemForTag:SJEdgeControlLayerTopItem_Back];
[backItem addTarget:self action:@selector(backItemWasTapped)];
-
修改间距
获取到 topAdapter 上的返回按钮, 并修改前后间距
SJEdgeControlButtonItem *backItem = [_player.defaultEdgeControlLayer.topAdapter itemForTag:SJEdgeControlLayerTopItem_Back];
backItem.insets = SJEdgeInsetsMake(20, 20);
[_player.defaultEdgeControlLayer.topAdapter reload];
将 bottomAdapter 上的播放按钮与全屏按钮交换位置
[_player.defaultEdgeControlLayer.bottomAdapter exchangeItemForTag:SJEdgeControlLayerBottomItem_Play withItemForTag:SJEdgeControlLayerBottomItem_FullBtn];
[_player.defaultEdgeControlLayer.bottomAdapter reload];