8

Is it possible to use:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;

in viewcontroller.m file?

0

3 Answers 3

9

hitTest:withEvent: method is declared in UIView class so you it can't be used in UIViewController subclasses directly.

But other touch-tracking methods such as touchesBegan:withEvent: etc are declared in UIResponder and so can be implemented in both UIView and UIViewController subclasses

6

Perhaps an alternative workaround is simply to subclass UIView , and in your init function of view controller assign the view controllers view to that UIView.

Eg. NavPanelViewController.m

- (id)init

    theView = [[NavPanelView alloc]init]; // declare theView in your header and in dealloc release
    self.view = theView;

Then you can override the pointInside method in your subclass.

2
  • 1
    I don't know why your is not the accepted answer, as it is the only one that truly answers the question.
    – Duck
    Commented Mar 24, 2012 at 12:06
  • 5
    Best practice would be to set a custom UIView in -loadView. The reason being to avoid prematurely loading the view.
    – codeperson
    Commented Jan 9, 2014 at 17:44
3

You can always define a specific delegate for handling the hitTest relevant info. In the hitTest:withEvent: in your UIView class's .m (implementation) file call the delegate's method, passing all your relevant info to the delegate to handle. Declare your ViewController class to implement the delegate like this:

@implementation MyViewController: UIViewController <HitTestDelegate>

This way, the actual implementation of the logic following user's tap will be in the MyViewController class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.