I am working on a customise UISlider where the MinimumValue is 0 and MaximumValue is 100. I want user to slow down the speed at the value of 50. For an example , if a user start sliding from 0 to 100 , it should work in a normal speed from 0-50 and then there should be a speed break at 50 and then the normal speed should be continued form 51-100.
Currently i have tried UISlider step size,
-(IBAction)valueChanged:(id)sender {
NSLog(#"Value : %f",roundf(_questionSlider.value));
float newStep = roundf((_questionSlider.value) / self.stepValue);
self.questionSlider.value = newStep * self.stepValue;
}
Related
I've tried to make a slider to show a percentage out of 100, but the label doesn't show that value correctly.
A UISlider has a default min and max of 0 and 1. So the slider is sending all kinds of fractional values as you move the slider such as 0.153343 and .53453545, etc. But you convert that number to an Int. That leaves you with only 0 and 1.
Either multiply the sender.value * 100 or change the slider's max value to 100.
Just set the maximumValue of the slider:
slider.maximumValue = 100
This will have the slider go between 0 and 100.
However, if you would not like to do this, try something like this:
#IBAction func valueChanged(sender: UISlider) {
let rounded = round(100 * sender.value) / 100
let final = rounded * 100
sliderLabel.text = "\(final)"
}
Made for Objective C. If anybody need.
float founded = roundf(100*self.volumeViewSlider.value)/100;
float final = founded*100;
I'm implementing a video player in which I've taken UISlider to track the progress of the movie. This would mean that the thumb of the slider should be at the max value when the movie finishes.
I'm not able to achieve this. Movie finishes before thumb reaches at the end. Could anybody please help me understand what could be the issue?
This is the code that I've written:
//I'm setting the min, max values of the UISlider and calculating the current value
progressBar.minimumValue = 0.0;
progressBar.maximumValue = (float)movie.duration;
progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;
Just use progressBar.value = (float)movie.currentPlaybackTime; instead of progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;
Max value should be equal to the frame width:
progressBar.minimumValue = 0.0;
progressBar.maximumValue = progressBar.frame.size.width;
progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;
Shouldn't it just be: progressBar.value = (float)movie.currentPlaybackTime ?
I mean, lets say movie duration is 60 sec, and the movie is at 15 sec (this is currentplaybacktime, I guess).
so:
progressbar min value is 0
progressbar max is 60
progressbar value should be between 0 and 60, and it is the value where the film is at right now: its 15.
Edit: You should also use: - setValue:animated:
Another idea: maybe you are not on the main thread. Make sure you are on the main thread when making ui changes.
In UISlider Control if I set "MinimumValue = 0" & "MaximimValue=2000" then I am not able to set the exact value. On release of slider thumb image it changes the value to + or - 5 to10. My slider width = 225px.
For example:- if I try to set the slider value to 100 then on release of slider thumb it shows me result like 105 or 95.
Code
IBOutlet UISlider * slider;
//"Slider" Object attached using XIB(.NIB)
slider.minimumValue = 0;
slider.maximumValue = 100;
//Attached Below Method Using XIB(.NIB) with "value Changed" event.
-(IBAction)slider_Change:(id)sender;
{
//Assigning value to UITextField
textFiled.text = [NSString stringWithFormat:#"%d",(((int) (slider.value)) * 20)];
}
Because you have set your slider range to be so large each pixel on the screen is equivalent to 8.888.
2000 / 255 = 8.8888888889
To get graduations of 1 you'll need to move the slider 1/8 of a pixel (this is impossible).
Alternatives are:
Make the slider longer
Reduce the slider range
Use a different control UIStepper
In addition to the answer by #rjstelling, it seems as if you are trying to convert the value of the slider to become an integer value. I believe that the default of the slider is a double value, this would cause the value to become rounded as it is increasing, since there will not be decimal values. Unless it is a requirement, see if you can use double.
textFiled.text = [NSString stringWithFormat:#"%f",(slider.value * 20.0)];
or if for some reason you'd want to restrict the level of decimal places you could go, you could do:
textField.text = [NSString stringWithFormat:#"%.1f", slider.value * 20.0];
This will give you the result of a decimal like 1.5 as your answer.
You could do anything with the decimal or even do something like %1.2f, %4.3f, or even %10.4f,
those will produce results like: 0.34, 0012.446, and something extreme like 000000345.1111
Hope this helps
Now i have a working Joystick, but I want to increase the characters speed.
I´m using this one at the moment: http://roadtonerdvana.wordpress.com/2013/09/20/jcinput-a-simple-joystick-for-sprite-kit/
I attached an Imagefile as the moving object, but it´s way too slow for my purpose.
Where and how can I change the speed?
If you read the post you'll know that the joystick returns a x and y value, each ranging from -1 to 1.
Every time you move the joystick, the properties x and y of it change accordingly, the maximum value is 1 and the minimum is -1.
In the update method, you could do something like this to adjust the speed :
-(void)update:(CFTimeInterval)currentTime {
// I'm using the magic number of 5 as an example of how to magnify the speed x5
float speedX = 5 * self.joystick.x;
float speedY = 5 * self.joystick.y;
[self.myLabel setPosition:CGPointMake(self.myLabel.position.x+speedX, self.myLabel.position.y+speedY)];
}
I have a UISlider with minimumValue 0 and maximumValue. I want to make an interval of 0.5 and display it in a label (it's working).
How can I set the interval of my slider? I tried solution to round the value... but I failed.
Thank you
float RoundValue(UISlider * slider) {
return roundf(slider.value * 2.0) * 0.5;
}
when i do something like that i take an approach like the following:
#define kSTEPFRACTION .5
SliderMin = 0
sliderMax = 20
and get the value withs something like that
value = slider.value*kSTEPFRACTION;
this will give you values between 0 and 10 in steps of 0.5
sebastian