思路:另外写一个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];
}
}
网友评论