在 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] 删除。
我来说两句