Search code examples
iosinterface-builderuislideruipangesturerecognizer

Link UIPanGestureRecognizer to UISlider?


I'm creating a musical app using libpd that has two ways of controlling the volume and pitch of a waveform - two independent UISliders and an XY pad using UIPanGestureRecognizer.

What I'd like to be able to do is to have the actions of the XY pad reflected by the sliders and so was wondering how that was possible? (i.e. the Y axis is already controlling volume but to see the slider react to it as well)

This is where I'm at with the separate controls.

// Volume slider
-(IBAction)sineVol:(id)sender
{
    UISlider *vslider = (UISlider *)sender;
    [PdBase sendFloat:vslider.value toReceiver:@"sine_vol"];
}

// Pitch slider    
-(IBAction)sinePitch:(id)sender
{
    UISlider *pslider = (UISlider *)sender;
    [PdBase sendFloat:pslider.value toReceiver:@"sine_pitch"];
}

// XY Pad
-(IBAction)sineXYPad:(UIPanGestureRecognizer *)trigger
{
    float sinepadHeight = sinexyview.bounds.size.height;
    float sinepadWidth = sinexyview.bounds.size.width;
    CGPoint location = [trigger locationInView:sinexyview];

    if ((location.y >= 0) && (location.y < sinepadHeight) && (location.x >= 0) && (location.x < sinepadWidth))
    {
    float sineVolXY = ((location.y) / 250);
    [PdBase sendFloat:sineVolXY toReceiver:@"sine_vol"];
}

    if ((location.y >= 0) && (location.y < sinepadHeight) && (location.x >= 0) && (location.x < sinepadWidth))
    {
    float sinePitchXY = ((location.x) / 5);
    [PdBase sendFloat:sinePitchXY toReceiver:@"sine_pitch"];
    }
}

Solution

  • Fixed this now - Added outlets for the sliders and then added the two lines below for each function.
    volumeSlider.value = sineVolXY;
    pitchSlider.value = sinePitchXY;