2013-02-18 67 views
0

這是我當前如何做如何使應用程序UISlider snappy?

- (IBAction)sliderDistanceChanged { 
    CGFloat sliderPosition = self.sliderDistance.value; 
    NSUInteger sliderIndex = [BGDistanceFilterStop indexForFilterEffect:sliderPosition]; 

    self.distanceFilterForCatalog = @([BGDistanceFilterStop numberValueOfDistance:sliderIndex]); 
    //self.distanceFilterForCatalog= @(self.sliderDistance.value).roundWithForDistanceFilter; 
    //[self.distanceFilter setTitle:self.distanceFilterForCatalog.distanceForm forState:UIControlStateNormal]; 
    [self.distanceFilter setTitle:[BGDistanceFilterStop stringValueOfDistance:sliderIndex] forState:UIControlStateNormal]; 

} 
- (IBAction)SliderNoLongerTouched:(id)sender { 
    CGFloat sliderIndex = [BGDistanceFilterStop sliderSnappedPosition:self.sliderDistance.value]; 
    self.sliderDistance.value=sliderIndex; 
} 

它基本上檢測self.sliderDistance.value然後根據舍入後設置的報告值。

一旦用戶不再聯繫,我改變self.sliderDistance.value

的立場,即是罰款。

但是,我想在用戶修改之前更改self.sliderDistance.value。但是,這與iOS用於跟蹤滑塊的雙手位置和值的變量是相同的。

那麼,如何安排按鈕捕捉到正確的位置而不改變self.sliderDistance.value?

回答

0

enter image description here

(IBAction)sliderDistanceChanged { 
    CGFloat sliderPosition = self.sliderDistance.value; 
    NSUInteger sliderIndex = [BGDistanceFilterStop indexForFilterEffect:sliderPosition]; 

    self.distanceFilterForCatalog = @([BGDistanceFilterStop numberValueOfDistance:sliderIndex]); 
    //self.distanceFilterForCatalog= @(self.sliderDistance.value).roundWithForDistanceFilter; 
    //[self.distanceFilter setTitle:self.distanceFilterForCatalog.distanceForm forState:UIControlStateNormal]; 
    [self.distanceFilter setTitle:[BGDistanceFilterStop stringValueOfDistance:sliderIndex] forState:UIControlStateNormal]; 

} 
- (IBAction)SliderNoLongerTouched:(id)sender { 
    CGFloat sliderIndex = [BGDistanceFilterStop sliderSnappedPosition:self.sliderDistance.value]; 
    self.sliderDistance.value=sliderIndex; 
} 

基本上它檢測到self.sliderDistance.value,然後根據舍入後設置的報告值。

一旦用戶不再聯繫,我改變self.sliderDistance.value

這很好的位置。

+1

圖像的相關性是什麼? – ekhumoro 2017-02-20 19:54:27

+0

@JimThio - 這個來自3年前問題的新答案僅僅是問題的重複?有一個很好但不相關的圖像? – foundry 2017-02-24 19:38:03

2

我假設這些操作中的每一個都與有問題的UISlider相關聯。第一個由valueChanged觸發,第二個由touchUpInside觸發。

在這種情況下,首先改變你的簽名,這些

- (IBAction)sliderDistanceChanged:(UISlider*)sender; 
- (IBAction)sliderNoLongerTouched:(UISlider*)sender; 

,讓您可以參考滑蓋sender代替self.sliderDistance(更簡單,更自足)。

修改sliderDistanceChanged

- (IBAction)sliderDistanceChanged:(UISlider*)sender; 
      //allocate the raw slider value to a variable 
      CGFloat rawValue = sender.value; 

      //calculate the snapped value 
      CGFloat snappedValue = [BGDistanceFilterStop sliderSnappedPosition:sender.value]; 

      //snap the slider in position 
      sender.value = snappedValue; 


     //now do the rest of your processing 
     //using rawValue if you want the raw value, 
     //snappedValue if you want the snapped value 

     } 

簡化sliderNoLongerTouched

- (IBAction)sliderNoLongerTouched:(id)sender { 
    sender.value = [BGDistanceFilterStop sliderSnappedPosition:sender.value]; 
}   

(你實際上並不在sliderDistanceChanged需要這個現在,作爲價值卡扣到位)

+0

完美地工作。現在非常活潑。 – 2013-02-19 09:36:24

相關問題