Use UIslider maximum and minimum values as coordinate range for UIView

Discussion in 'iOS Programming' started by lexk, Apr 28, 2013.

  1. lexk macrumors newbie

    Joined:
    Aug 8, 2010
    #1
    The problem I'm looking to overcome at the moment is trying to use the minimum (25.1751) and maximum (81) values of a UISlider as the minimum and maximum x coordinates of the grey UIView.
    In other words, can I make the left edge of the UIView output 25.1751 and the right edge output 81?

    The values of the sliders aren't default on account of converting them to frequency values for an oscillator, and currently the values outputted by the UIView are outside of the range I want. I've tried reducing the maximum output of the UIView using math formulas but I can't raise the minimum.
    I hope that made some sense!

    Here's where I'm at with the code so far and thanks in advance for any help!
    Code:
    - (IBAction)sawXYPad:(UIPanGestureRecognizer *)trigger {
        float sawpadHeight = sawxyview.bounds.size.height;
        float sawpadWidth = sawxyview.bounds.size.width;
        CGPoint location = [trigger locationInView:sawxyview];
    
        if ((location.y >= 0) && (location.y < sawpadHeight) && (location.x >= 0) && (location.x < sawpadWidth)) {
            float maxX = sawPSlider.maximumValue;
            float minX = sawPSlider.minimumValue;
            float sawPitchXY = (location.x > minX) && (location.x < maxX);
            sawPSlider.value = sawPitchXY;
            [PdBase sendFloat:sawPitchXY toReceiver:@"saw_pitch"];
        }
    }
    [​IMG]
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    If I am understanding correctly, you could take the x coordinate of the location CGPoint. You would then do

    Code:
    
    float position = (location.x/(81-25.1751)) + 25.1751;
    
    
     
  3. lexk thread starter macrumors newbie

    Joined:
    Aug 8, 2010
    #3
    Thank you, this is great for setting the lowest/left x coordinate but then how would I go about setting the highest/right side?
     
  4. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #4
    I am a bit confused. this line should give you the value of the finger touch between your minimum and maximum. I guess I am misunderstanding what you are trying to do.
     
  5. lexk thread starter macrumors newbie

    Joined:
    Aug 8, 2010
    #5
    My mistake - you were right, I just edited it to
    Code:
    float position = (location.x/(41.725-25.1751)) + 25.1751;
    to help scale it within the UIView.
    Thanks so much for your help!
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    If the "right edge output" is 81, why are you using 41.725?
     
  7. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #7
    Yeah, if the values are as he described, does my solution seem to make sense?
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    To me, it makes perfect sense.
     

Share This Page