I'm doing some hit testing and have run into a confusing situation.
I have two buttons "favoriteButton" and "shareButton". The following code results in 'a' and 'b' being true even though the buttons do not overlap:
CGPoint dunno = CGPointMake(11, 7);
BOOL a = [self.favoriteButton pointInside:dunno withEvent:nil];
BOOL b = [self.shareButton pointInside:dunno withEvent:nil];
and just to prove it, here is the description output for the two buttons at the point that this code is being called.
Printing description of _favoriteButton:
<UIButton: 0x5da8c90; frame = (10 6; 37 35); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5da8d40>>
Printing description of _shareButton:
<UIButton: 0x5da7150; frame = (46 6; 30 35); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5da59b0>>
Whats going on here? Am I misunderstanding what the output should be?
Well @Nippysaurus according to the documentation
http://developer.apple.com/library/iOS/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/pointInside:withEvent:
A point that is in the receiver’s local coordinate system (bounds).
That means that point CGPoint dunno = CGPointMake(11, 7); is inside the view as the bounds of the view will be different that the frame of the same view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With