- (void)loadView {
[super loadView];
preBgView = [[UIView alloc] initWithFrame:CGRectMake(10, 70, Screen_Width-20, 90)];
preBgView.backgroundColor = UIColorFromRGB(0x888888);
[self.view addSubview:preBgView];
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];
[preBgView addGestureRecognizer:panGesture];
sliderBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, preBgView.frame.size.width, preBgView.frame.size.height)];
sliderBgView.layer.borderWidth = 5;
sliderBgView.layer.borderColor = UIColorFromRGB(999999).CGColor;
sliderBgView.userInteractionEnabled = YES;
[preBgView addSubview:sliderBgView];
leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, sliderBgView.frame.size.height)];
leftBtn.backgroundColor = [UIColor redColor];
[sliderBgView addSubview:leftBtn];
UIPanGestureRecognizer *leftPanGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleLeftPanGesture:)];
[leftBtn addGestureRecognizer:leftPanGesture];
rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(sliderBgView.frame.size.width-20, 0, 20, sliderBgView.frame.size.height)];
rightBtn.backgroundColor = [UIColor yellowColor];
[sliderBgView addSubview:rightBtn];
UIPanGestureRecognizer *rightPanGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleRightPanGesture:)];
[rightBtn addGestureRecognizer:rightPanGesture];
}
#pragma mark - Gesture
-(void)handlePanGesture:(UIPanGestureRecognizer *)sender {
//得到拖过程中的xy坐标
CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];
if(sender.state==UIGestureRecognizerStateChanged) {
// 根据拖动位置,快进视频预览进度
}
}
-(void)handleLeftPanGesture:(UIPanGestureRecognizer *)sender {
//得到拖过程中的xy坐标
CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];
if (translation.x < 0 || sliderBgView.frame.size.width+sliderBgView.frame.origin.x < translation.x+rightBtn.frame.size.width*2 ) {
return;
}
CGFloat intX = translation.x - sliderBgView.frame.origin.x;
if(sender.state==UIGestureRecognizerStateChanged)
{
CGRect rect = sliderBgView.frame;
rect.origin.x = translation.x;
rect.size.width = sliderBgView.frame.size.width - intX;
sliderBgView.frame = rect;
rect = rightBtn.frame;
rect.origin.x = sliderBgView.frame.size.width-rightBtn.frame.size.width;
rightBtn.frame = rect;
}
}
-(void)handleRightPanGesture:(UIPanGestureRecognizer *)sender {
//得到拖过程中的xy坐标
CGPoint translation = [(UIPanGestureRecognizer *)sender locationInView:preBgView];
if (translation.x+rightBtn.frame.size.width >= preBgView.frame.size.width) {
return;
}
CGFloat intX = sliderBgView.frame.size.width+sliderBgView.frame.origin.x - translation.x;
if(sender.state==UIGestureRecognizerStateChanged)
{
CGRect rect = sliderBgView.frame;
rect.size.width = sliderBgView.frame.size.width - intX;
sliderBgView.frame = rect;
rect = rightBtn.frame;
rect.origin.x = sliderBgView.frame.size.width-rightBtn.frame.size.width;
rightBtn.frame = rect;
}
}
iMoive拖动选择框
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.循环滚动 每次滚动后都将scrollview的offset设置为中间的一页 若本次滚动是向前一页滚动,则把三页...