需求:做一個(gè)滑動(dòng)價(jià)格選擇器
這邊主要用到的控件:
1、兩個(gè)ImageView
2、一個(gè)顯示灰色的View
3、一個(gè)顯示中間區(qū)域的View
主要代碼展示:
-(void)leftHandMove:(UIPanGestureRecognizer*)pan{
? ? CGPointpoint = [pantranslationInView:self.leftImageView];
? ? CGFloatx =self.leftImageView.center.x+ point.x;
? ? if(x >=0&& x<=self.rightImageView.center.x- (self.frame.size.width*self.mixPrice/self.maxPrice)) {
? ? ? ? [selfaddSubview:self.leftImageView];
? ? ? ? self.leftImageView.center = CGPointMake(x, self.leftImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }elseif(x <=0){
? ? ? ? [selfaddSubview:self.leftImageView];
? ? ? ? self.leftImageView.center = CGPointMake(0, self.leftImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }else if (x >= self.rightImageView.center.x - (self.frame.size.width*self.mixPrice/self.maxPrice)){
? ? ? ? [selfaddSubview:self.leftImageView];
? ? ? ? self.leftImageView.center = CGPointMake(self.rightImageView.center.x - (self.frame.size.width*self.mixPrice/self.maxPrice), self.leftImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }
}
-(void)rightHandMove:(UIPanGestureRecognizer*)pan{
? ? CGPointpoint = [pantranslationInView:self.rightImageView];
? ? CGFloatx =self.rightImageView.center.x+ point.x;
? ? if(x >=self.leftImageView.center.x+self.frame.size.width*self.mixPrice/self.maxPrice&& x<=self.frame.size.width) {
? ? ? ? [self addSubview:self.rightImageView];
? ? ? ? self.rightImageView.center = CGPointMake(x, self.rightImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }else if (x <= self.leftImageView.center.x + self.frame.size.width*self.mixPrice/self.maxPrice){
? ? ? ? [self addSubview:self.rightImageView];
? ? ? ? self.rightImageView.center = CGPointMake(self.leftImageView.center.x + self.frame.size.width*self.mixPrice/self.maxPrice, self.rightImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }elseif(x >=self.frame.size.width){
? ? ? ? [self addSubview:self.rightImageView];
? ? ? ? self.rightImageView.center = CGPointMake(self.frame.size.width, self.rightImageView.center.y);
? ? ? ? [pansetTranslation:CGPointZero inView:self];
? ? ? ? [self judgecontentPointCenterB];
? ? }
}
主要根據(jù)滑動(dòng)的進(jìn)度來(lái)計(jì)算位置,供大家參考
如果有問(wèn)題請(qǐng)聯(lián)系我郵箱:578145120@qq.com或者添加我的微信:chuan88zl