Iphone (UIView*)是否在viewcontroller中进行hitTest?
可以使用吗Iphone (UIView*)是否在viewcontroller中进行hitTest?,iphone,ipad,Iphone,Ipad,可以使用吗 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; 在viewcontroller.m文件中?任何教程请?hitTest:withEvent:方法在UIView类中声明,因此不能直接在UIViewController子类中使用 但是其他触摸跟踪方法,如touchsbegind:withEvent:等在UIResponder中声明,因此可以在UIView和UIViewController子类中实现您始终可以定义
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
在viewcontroller.m文件中?任何教程请?hitTest:withEvent:方法在UIView类中声明,因此不能直接在UIViewController子类中使用
但是其他触摸跟踪方法,如
touchsbegind:withEvent:
等在UIResponder中声明,因此可以在UIView和UIViewController子类中实现您始终可以定义一个特定的委托来处理hitTest相关信息。在UIView类的.m(实现)文件中的hitTest:withEvent:
中,调用代理的方法,将所有相关信息传递给代理进行处理。声明ViewController类以实现如下委托:
@implementation MyViewController: UIViewController <HitTestDelegate>
@实现MyViewController:UIViewController
这样,用户点击后的逻辑的实际实现将在MyViewController类中。也许另一种解决方法只是将UIView子类化,并在view controller的init函数中将view controller视图分配给该UIView 例如。 NavPanelViewController.m
- (id)init
theView = [[NavPanelView alloc]init]; // declare theView in your header and in dealloc release
self.view = theView;
然后可以重写子类中的pointInside方法 我不知道为什么您的答案不被接受,因为它是唯一真正回答这个问题的答案。最佳做法是在
-loadView
中设置自定义UIView。原因是为了避免过早加载视图。