是否有可能在viewcontroller.m文件中使用(UIView *)hitTest在viewcontroller?
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
?任何教程請問?
是否有可能在viewcontroller.m文件中使用(UIView *)hitTest在viewcontroller?
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
?任何教程請問?
hitTest:withEvent:
方法在UIView類中聲明,所以你不能直接在UIViewController子類中使用它。
但其他觸摸跟蹤方法,如touchesBegan:withEvent:
等在UIResponder聲明,所以可以在兩個UIView的實現和子類的UIViewController
你總是可以定義一個特定的委託處理相關則hitTest信息。在您的UIView類的.m(實現)文件中的hitTest:withEvent:
中調用委託的方法,將所有相關信息傳遞給委託來處理。聲明你的ViewController類來實現這樣的委託:
@implementation MyViewController: UIViewController <HitTestDelegate>
這樣的邏輯下用戶的敲擊實際執行將在MyViewController類。
也許一個替代的解決方法是簡單地爲UIView子類,並在您的視圖控制器的init函數分配視圖控制器視圖到該UIView。
例如, NavPanelViewController.m
- (id)init
theView = [[NavPanelView alloc]init]; // declare theView in your header and in dealloc release
self.view = theView;
然後你就可以覆蓋在子類中pointInside方法。
我不知道你爲什麼不被接受的答案,因爲它是唯一真正回答問題的答案。 – SpaceDog 2012-03-24 12:06:02
最佳做法是在'-loadView'中設置一個自定義的UIView。原因是爲了避免過早加載視圖。 – jonsibley 2014-01-09 17:44:15