混音控制台应用中的多个平移手势

时间:2013-08-10 17:10:50

标签: iphone ios objective-c ipad uigesturerecognizer

我希望我的iPad调音台应用能够在用户用多个手指触摸时同时移动多个滑块,就像在现实生活中一样。

我已经为单个平移手势(UIPanGestureRecognizer)实现了我的逻辑。在这种情况下如何添加多点触控功能?

要求iOS 5.1兼容。

编辑以供参考,以下是现实混音控制台上的手势:

enter image description here

1 个答案:

答案 0 :(得分:5)

您可以为每个滑块创建单独的手势识别器,例如假设你有一个收集渠道:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.sliders enumerateObjectsUsingBlock:^(UIView *slider, NSUInteger idx, BOOL *stop) {
        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        [slider addGestureRecognizer:pan];
    }];
}

然后,手势识别器会单独处理每一个(令人惊讶的是,无需同时使用shouldRecognizeSimultaneouslyWithGestureRecognizer识别它们):

- (void)handlePan:(UIPanGestureRecognizer *)gesture
{
    CGPoint translation = [gesture translationInView:gesture.view];

    gesture.view.transform = CGAffineTransformMakeTranslation(0.0, translation.y);

    if (gesture.state == UIGestureRecognizerStateEnded)
    {
        CGRect frame = gesture.view.frame;
        frame.origin.y += translation.y;
        gesture.view.frame = frame;
        gesture.view.transform = CGAffineTransformIdentity;
    }
}