Property "targetView" not found on object of type "MenuView"

Discussion in 'iOS Programming' started by moonman239, Aug 13, 2015.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I am trying to get some UIViews to register touch events. Per Apple's recommendation, I am overriding UIView's hitTest method. I am using this code, which I copied & pasted from Apple's documentation:

    Code:
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    // Convert the point to the target view's coordinate system.
    // The target view isn't necessarily the immediate subview
    CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self];
    
    if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) {
    
    // The target view may have its view hierarchy,
    // so call its hitTest method to return the right hit-test view
    return [self.targetView hitTest:pointForTargetView withEvent:event];
    }
    
    return [super hitTest:point withEvent:event];
    }
    
    However, for some reason, Xcode says there's no targetView property. Am I using old code? If so, will someone please post either the right code or a link to it? Thanks!

    Edit: I am using the iOS 8.4 SDK.
     
  2. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #2
    OK, so here's some code that actually works (Note: I did try using the pointInside method; however, it didn't work.)

    Code:
    -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    
    {
    
        BOOL (^predicateBlock)(id evalObject, NSDictionary *bindings) = ^BOOL(id evalObject, NSDictionary *bindings)
    
        {
    
            CGRect frame = [evalObject frame];
    
            return (CGRectContainsPoint(frame, point) && ![evalObject isKindOfClass:[UIImageViewclass]]);
    
        };
    
        NSArray *views = [self.subviewsfilteredArrayUsingPredicate:[NSPredicatepredicateWithBlock:predicateBlock]];
    
       
    
        return [views firstObject];
    
    }
    
     

Share This Page