Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:10:11+00:00 2026-06-02T16:10:11+00:00

so I have a mutable array that holds several circles which are UIViews. right

  • 0

so I have a mutable array that holds several circles which are UIViews.
right now I have my touches began method setup like this.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

    CGPoint touchLocation = [touch locationInView:self.view];

    for (Circle *circle in playerOneCircles)
    {
        if ([circle.layer.presentationLayer hitTest:touchLocation])
        {
            [circle playerTap:nil];
            break;
        } 
    }   
}

this works fine. but it gives problems with overlapping views.
I want other UIviews to also respond to the touchesbegan method (that would then trigger other methods). but if 2 objects would overlap then my touchesbegan would trigger the wrong method.

so I would like to define multiple UITouches that only respond to certain objects instead of anyObject. how would I have to define the UITouch to only work with objects from my mutable array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:10:12+00:00Added an answer on June 2, 2026 at 4:10 pm

    EDIT

    Added comments to answer your comment to explain the code.

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // We want to find all the circles that contain the touch point.
        // A circle does not have to be "on top" (or even visible) to be touched.
        // All circles that contain the touch point will be added to the touchedCircles set.
        NSMutableSet *touchedCircles = [NSMutableSet set];
    
        // To support multiple touches, we have to look at every touch object.
        for (UITouch *touch in touches) {
            CGPoint touchLocation = [touch locationInView:self.view];
            // Search through our collection of circle objects.  Any circle that
            // contains this touch point gets added to our collection of touched
            // circles.  If you need to know which UITouch is "touching" each circle,
            // you will need to store that as well.
            for (Circle *circle in playerOneCircles) {
                if ([circle containsPoint:touchLocation]) {
                    [touchedCircles addObject:circle];
                }
            }
        }
    
        // We have completed our search for all touches and all circles.  If
        // and circle was touched, then it will be in the set of touchedCircles.
        if (touchedCircles.count) {
            // When any circle has been touched, we want to call some special method
            // to process the touched circle.  Send the method the set of circles, so it
            // knows which circles were touched.
            [self methodAWithTouchedCircles:touchedCircles];
        } else {
            // None of our circles were touched, so call a different method.
            [self methodB];
        }
    }
    

    You would implement containsPoint for a Circle something like this…

    - (BOOL)containsPoint:(CGPoint)point
    {
        // Since each of our objects is a circle, to determine if a point is inside
        // the circle, we just want to know if the distance between that point and
        // the center of the circle is less than the radius of the circle.
        // If your circle is really contained inside a view, you can compute the radius
        // as one-half the width of the frame.
        // Otherwise, your circle may actually have its own radius property, in which case
        // you can just use the known radius.
        CGFloat radius = self.frame.size.width *.5;
    
        // This is just the Pythagorean Theorem, or instance formula.
        // distance = sqrt((x0-x1)^2 + (y0-y1)^2)
        // and we want to check that
        //     distance < radius
        // By simple algebra, that is the same as checking
        //     distance^2 < radius^2
        // which saves us from having to compute the square root.
        CGFloat diffX = self.center.x - point.x;
        CGFloat diffY = self.center.y - point.y;
        return (diffX*diffX) + (diffY*diffY) < radius*radius;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mutable array that is retained and storing several objects. At some
I have a mutable array which stores sprites but the problem is that the
I have mutable string array named arrayout. It is having 3 element .Now I
I have a mutable array that has been retained. This array contain dictionaries with
I have a mutable array of custom objects. I want to filter that array
I have a UITableView that was created from data coming from a mutable array.
I have an non-mutable array that only needs to have numbers. How would I
I've a mutable array that holds instances of a model object. That model object
I am new to iphone development .I have mutable array recent in which the
Here I have added no of co-ordinates to dataForPlot (which is an mutable array).I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.