如何获得多点触摸的多个位置UITapGestureRecognizer(How to get mul

2019-10-21 11:37发布

我有一个UITapGestureRecognizer在我看来,我可以得到它与下面的代码精细触摸的位置。 现在,如果我改变触摸该识别器的数量为2(或更多),但它仍然给了我一个位置。 我怎样才能获得两个触摸的两个位置?

tapGesture.locationInView(self.view)

在迅速请帮助。

Answer 1:

而不是使用locationInView ,使用locationOfTouch让每个抽头的位置:

let tapLocation1 = tapGesture.locationOfTouch(0, inView: self.view)
let tapLocation2 = tapGesture.locationOfTouch(1, inView: self.view)


Answer 2:

尝试在开关multipleTouchEnabled您的自定义视图属性

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];

    if (self) {

        self.multipleTouchEnabled = YES;

    }

    return self;
}


文章来源: How to get multiple locations of multi touch UITapGestureRecognizer
标签: ios xcode swift