Re: Checking if a touch is within a UIButton’s bounds.
Re: Checking if a touch is within a UIButton’s bounds.
- Subject: Re: Checking if a touch is within a UIButton’s bounds.
- From: Dave DeLong <email@hidden>
- Date: Sun, 18 Apr 2010 09:05:38 -0600
Is "self.view" the same thing as "button"? You're using the former to produce a CGPoint, but the latter to produce a bounding rectangle. My guess is that they're not the same, which means the point is in a different coordinate system than "button.bounds".
HTH,
Dave
On Apr 18, 2010, at 9:02 AM, Joshua Garnham wrote:
> I am trying to make an if statement which will check whether the users touch is within a
> UIButton's bounds. I thought this would be an easy affair as UIButton
> is a subclass of UIView, however my code doesn't seem to work.
> This is the code I have been using.
> - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
> NSArray *array = [touches allObjects];
> UITouch *specificTouch = [array objectAtIndex:0];
> currentTouch = [specificTouch locationInView:self.view];
> if (CGRectContainsPoint(button.bounds, currentTouch)) {
> //Do something.
> }
> //Else do nothing.
> }
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden