[Help] Increasing UISlider Value by 0.1

Discussion in 'iOS Development' started by cocotutch, Aug 25, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Firstly, I have searched High and Low in the Docs, Google and my mind and I seriously can't seem to figure this out, I found some code on the net that doesn't seem to work too.

    My problem is, I have Swipe Detection code inside TouchesMoved, and when I swipe, I want UISlider's Value to Increase by 0.1 every horizontal swipe if that is possible, how can I achieve this?

    Now, This may be a basic question, but again I have used the Docs, Google and my own Mind before coming here. So cut me some slack.

    Please Register or Log in to view images



    Thanks,

    cocotutch
  2. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    [OBJC]
    slider.value = slider.value + 1;
    [/OBJC]
    Should work, although i've never played with UISlider.
  3. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    That will add 1, and if you are using the slider's default value, it will set it to the max.

    In any case, it would be:
    [objc]slider.value += .1[/objc]

    However, swiping everytime to add .1 doesn't sound like a good UI to me...
  4. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Yeah, simple mistake, i'm sure he would have figured that out.
    And i agree to your final statement.
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Isn't the whole point of UISlider to let the user define a value by sliding it? Why would you create a slider, and then change its value manually with a swipe, rather than using it how intended?
  6. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Exactly. Use a UIProgressView if you're going to make something like this.
  7. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    I think this would clearly go against the Human Interface Guidelines.
  8. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I agree that this is not at all a practical way of doing things (unless there is something cocotouch is not telling us), and I find spoonforknife's statement to be right on.

    However, for the sake of the question, here's an answer:

    If you want the the changes you make the the slider's value to be animated, you can't just do

    [OBJC]slider.value += .1;[/OBJC] - You'll need to use this method:

    [OBJC]
    - (void)setValue

    Please Register or Log in to view images

    float)value animated

    Please Register or Log in to view images

    BOOL)animated

    // so, in practice -

    // dot syntax
    [mySlider setValue:mySlider.value + 0.1 animated:YES];

    // standard accessor ("getter") method
    [mySlider setValue:[mySlider value] + 0.1 animated:YES];

    [/OBJC]

    EDIT: Because you are using an unconventional way to update a sliders value, you'll definitely want animation.

    EDIT 2: I seriously don't believe that you did more than glance at the documentation. Didn't you see that the 'value' property is a float? That float by default can range between 0.0 and 1.0, which means any sort of addition or subtraction you do is going to involve a decimal value, that you wanted in the first place (tenths).

    I don't mind helping - at all, but I just find it odd.
  9. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Im using TouchesMoved to control the UISlider because it's (1) invisible and (2) controlling the iPod Volume

    Please Register or Log in to view images

    Unorthodox I know.......

    Im getting a weird error, I have code that detects which direction the swipe is in, in my test project it all works, but when I implement it into this project, the touch, no matter what direction, INCREASES the UISlider value.

    In my test project, swiping left decreases and swiping right increases. Not the case in this project, what is going on?

    Please Register or Log in to view images

    Please Register or Log in to view images



    Thanks,

    coco
  10. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    You need to create an actual volume controller. Using MPVolumeView is not recommended (by me). It is far too weighty an object, in my opinion.

Share This Page