Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone (UIView*)是否在viewcontroller中进行hitTest?_Iphone_Ipad - Fatal编程技术网

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。原因是为了避免过早加载视图。