Skip to content

如何修改控制层上`Adapter`的视图约束? (如何在控制层的其他区域添加自定义视图?)

changsanjiang edited this page Oct 10, 2020 · 3 revisions

如下, 在bottomAdapter的顶部区域添加自定义视图:

301602300739

代码实现:

    UIView *redView = [UIView.alloc initWithFrame:CGRectZero];
    redView.backgroundColor = UIColor.redColor;
    // 添加自定义视图到底部容器视图中
    [_player.defaultEdgeControlLayer.bottomContainerView addSubview:redView];
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.offset(44);
    }];
    
    // 修改bottomAdapter的约束
    _player.controlLayerAppearObserver.appearStateDidChangeExeBlock = ^(id<SJControlLayerAppearManager>  _Nonnull mgr) {
        __strong typeof(_self) self = _self;
        if ( !self ) return;
        // 仅在控制层显示后更新约束
        if ( mgr.isAppeared ) {
            [self.player.defaultEdgeControlLayer.bottomAdapter mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.offset(44);
            }];
        }
    };