[英]Hit Test in UIView in Objective C
在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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.