在UIViewController中,我要添加一个名为testView的UIView
@property(nonatomic) UIView * testView;
-(UIView *)testView{
if (!_testView) {
_testView = [UIView new];
_puzzleView.translatesAutoresizingMaskIntoConstraints = NO;
}
return testView
}
然后将那个View添加到ViewController。我想在testView中检测触摸。如何在ViewController中的UIView中添加hitTest方法
答案 0 :(得分:0)
在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
}
}