美文网首页
视频选择条Cell实现,并添加选中蓝色边框

视频选择条Cell实现,并添加选中蓝色边框

作者: Chase_Eleven | 来源:发表于2017-08-15 11:07 被阅读0次

    思路:另外写一个UIView,点击时改变其Center

    -(UIScrollView *)videoScrollSelectView:(NSArray *)videoView{
        if (!_videoScrollSelectView) {
            _videoScrollSelectView  = [[UIScrollView alloc] init];
            _videoScrollSelectView.frame = CGRectMake(0, 0, HHBWIDTH, 88);
            _videoScrollSelectView.backgroundColor = [UIColor whiteColor];
            _videoScrollSelectView.showsHorizontalScrollIndicator = NO;
            [self.contentView addSubview:_videoScrollSelectView];
            
            //选中边框
            _videoBorderView = [[UIView alloc] init];
            _videoBorderView.size = CGSizeMake(122, 70);
            _videoBorderView.backgroundColor = [UIColor clearColor];
            _videoBorderView.userInteractionEnabled = NO;
            _videoBorderView.layer.masksToBounds = YES;
            _videoBorderView.layer.borderColor = mainColor.CGColor;
            _videoBorderView.layer.borderWidth = 1.0;
            [_videoScrollSelectView addSubview:_videoBorderView];
            
            for (int i=0; i<videoView.count; i++) {
                HuCourseVideoModel *model = videoView[i];
                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15+125*i, 10, 120, 68)];
                imageView.backgroundColor = [HuConfigration uiColorFromString:@"#A5A5A5"];
                imageView.image = model.image;
                imageView.userInteractionEnabled = YES;
                imageView.tag = 100+i;
                UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectVideo:)];
                [imageView addGestureRecognizer:singleTap];
                if (i == 0) { //默认选中第一个
                    _videoBorderView.center = imageView.center;
                }
                [_videoScrollSelectView addSubview:imageView];
            }
            _videoScrollSelectView.contentSize = CGSizeMake(30+120*videoView.count+5*(videoView.count-1), 88);
        }
        return _videoScrollSelectView;
    }
    
    //点击时改变边框center
    -(void)selectVideo:(UIGestureRecognizer *)UIGestureRecognizer{
        if (self.delegate && [self.delegate respondsToSelector:@selector(selectVideo:)]) {
            _videoBorderView.center = UIGestureRecognizer.view.center;
            [self.delegate selectVideo:UIGestureRecognizer.view.tag];
        }
    }
    

    相关文章

      网友评论

          本文标题:视频选择条Cell实现,并添加选中蓝色边框

          本文链接:https://www.haomeiwen.com/subject/beumrxtx.html