iPhone上UISlider的彈性效果

[英]Elastic effect on UISlider on iPhone


I have four points on UISlider at 0, 1, 2 and 3. I want that when thumb position is from 0-1, it should come back to 0 but with elastic effect. Similar for 1-2, 2-3. This implementation will give me an edge in my application.

我在UISlider上有0分,1分,2分和3分。我希望當拇指位置從0到1時,它應該回到0但具有彈性效果。類似1-2,2-3。這個實現將使我在我的應用程序中占據優勢。

I have tried it with no elastic effect. But it does not look good.

我試過沒有彈性效果。但它看起來並不好。

3 个解决方案

#1


3  

Tell your slider to send an action on the “Touch Up Inside” event (UIControlEventTouchUpInside). Hook the action up to this method:

告訴您的滑塊在“Touch Up Inside”事件(UIControlEventTouchUpInside)上發送操作。將操作掛鈎到此方法:

- (IBAction)dragEndedWithSlider:(UISlider *)sender {
    CGFloat roundedValue = roundf(sender.value);
    [sender setValue:roundedValue animated:YES];
}

You can use truncf instead of roundf if that's what you really want.

如果這是你真正想要的,你可以使用truncf而不是roundf。

#2


2  

Bind this method to slider Value Changed in Interface builder

將此方法綁定到“接口”構建器中的“已更改值”滑塊

   -(IBAction)sliderChanged:(id)sender {

        slider.value = (int)slider.value;
    }

#3


2  

You could subclass UISlider and add this:

你可以繼承UISlider並添加它:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    CGFloat floorValue = floor(self.value);

    if ((self.value - floorValue) > 0.5) {

        [self setValue: floorValue + 1.0 animated: YES];

    } else {

        [self setValue: floorValue animated: YES];
    }
}

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/02/23/ae70c83e76a4e026383d7771b589f14d.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com