开发者

(UIView *)hitTest in viewcontroller?

Is it possible to use

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

in viewcontroller.m file?开发者_如何学Python any tutorial pls?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜