OGeek|极客世界-中国程序员成长平台

标题: ios - 启用语音后如何从自定义 View 上的点击位置获取 CGPoint? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:43
标题: ios - 启用语音后如何从自定义 View 上的点击位置获取 CGPoint?

我正在将我的应用设置为与旁白功能兼容。我有一个图表,我可以单击 -accessibilitiHint()。我需要确认双击时的用户操作,甚至可以通过accessibilityActivate() 获得。触摸点需要在单击时检索。

现在有什么方法可以在我的 View 上执行单击时获取用户触摸点吗?



Best Answer-推荐答案


对于 Objective-C

第 1 步:将 TapeGesture 识别器添加到您的 View 中

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self actionselector(tapGestureHandler];
tapGesture.delegate = self;   
[yourView addGestureRecognizer:tapGesture];

第二步:实现手势委托(delegate)方法

- (BOOL)gestureRecognizerUIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizerUIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

第 3 步:实现手势处理程序

- (void)tapGestureHandlerUITapGestureRecognizer *)gesture
{
    CGPoint touchPoint = [gesture locationInView:yourView];
}

关于ios - 启用语音后如何从自定义 View 上的点击位置获取 CGPoint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44151511/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4