目标 C 中 UIView 中的命中测试

用户10150355

在 UIViewController 中,我添加了一个名为 testView 的 UIView

@property(nonatomic) UIView * testView;

-(UIView *)testView{
    if (!_testView) {
        _testView = [UIView new];

        _puzzleView.translatesAutoresizingMaskIntoConstraints = NO;

  }
return testView

}

然后我将该视图添加到 ViewController。我想检测 testView 中的触摸。如何在 ViewController 中的 UIView 中添加 hitTest 方法

堆栈史蒂文

在 ViewController 中添加以下代码:

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    CGPoint point = [[touches anyObject] locationInView:self];
    point = [self.testView.layer convertPoint:point fromLayer:self.layer]; 
    if ([self.testView.layer containsPoint:point]) {
        //touch on the testView
    }
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章