将UIPanGestureRecognizer链接到UISlider?

时间:2013-04-10 12:41:00

标签: ios interface-builder uislider uipangesturerecognizer

我正在使用libpd创建一个音乐应用程序,它有两种控制波形音量和音高的方法 - 两个独立的UISliders和一个使用UIPanGestureRecognizer的XY平板。

我希望能够做的是让滑块的动作由滑块反射,所以想知道这是怎么回事? (即Y轴已经控制了音量,但也看到了滑块对它的反应)

这是我使用单独控件的地方。

// 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"];
    }
}

1 个答案:

答案 0 :(得分:0)

现在修复此问题 - 添加了滑块的插座,然后为每个功能添加了以下两行 volumeSlider.value = sineVolXY;
pitchSlider.value = sinePitchXY;