• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Checking if a touch is within a UIButton’s bounds.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Checking if a touch is within a UIButton’s bounds. (From: Joshua Garnham <email@hidden>)

  • Prev by Date: Checking if a touch is within a UIButton’s bounds.
  • Next by Date: Re: How do I get a file reference w/o relying on the path?
  • Previous by thread: Checking if a touch is within a UIButton’s bounds.
  • Next by thread: scrollPoint: and smooth scrolling depend on current modifierFlags?
  • Index(es):
    • Date
    • Thread