Questions tagged [cgrectintersectsrect]

CGRectIntersectsRect returns whether two rectangles intersect in iOS, macOS, tvOS and watchOS.

CGRectIntersectsRect is going to return true if any part of rect1 lies inside of rect2.

CGRectIntersectsRect is useful for more than just selections. You can use it to see if you need to draw something. If you’re managing a bunch of objects being drawn in a view, call CGRectIntersectsRect with the visible rectangle as a very fast test to see if you should draw that object or not. The questions related to this can be tagged with .

Resource:

Reference:

CGRectIntersectsrect Class reference

Sample:

CGRect container = CGRectMake (0.0, 0.0, 100.0, 200.0);
CGPoint point = CGPointMake (50.0, 100.0);

if (CGRectContainsPoint(container, point)) {
    NSLog (@"contains point!");
}

Related SO questions:

  1. CGRectIntersectsRect() in iOS

  2. The questions related to this can be tagged with cgrectintersectsrect

18 questions
1
vote
1 answer

How to access a layer inside UIView custom class generate with Paintcode?

I'm using Paintcode V3 and last Xcode for my project. In Paintcode I draw a red path, kind of "clock hand" with a radius variable to be able to rotate it. In my Xcode project, this custom UIView is added to a main view. When the red path is…
cmii
  • 3,556
  • 8
  • 38
  • 69
1
vote
2 answers

Check to see if a CGRect intersects with an array of CGRects

I'm trying to see if a CGRects intersects with any other CGRects in an array before initializing the CGRect, but I am yet to find a fool proof method that works. Note that intersection is the array of CGRects. Any takes on how to do this? The method…
MJJLAM
  • 163
  • 1
  • 13
1
vote
2 answers

Swift: Which direction a UIView is being intersected from?

I am using CGRectIntersectsRect to test if blueView (being dragged) has intersected with redView (stationary). However, I need to know if redView was intersected by blueView from red's top, bottom, right or left? Is there a CG method to accomplish…
Kashif
  • 4,642
  • 7
  • 44
  • 97
1
vote
1 answer

Filter nsmutable array by CGRectIntersectsRect

I wanna extract from an array of SKSpriteNode only the elements that intersect with a predeterminated frame. I can do it by a for iteration: for (SKSpriteNode* Object in Array) { if (CGRectIntersectsRect(Frame,Object.frame)) { …
user31929
  • 1,115
  • 20
  • 43
1
vote
2 answers

Collision of 2 imageView ios

I am having 2 images and i need to collide them properly. I tried many solutions but can't collide them properly. Here are the images Image 1 Image 2 I tried CGRectIntersectsRect(), but its not working properly because images are colliding before…
Samkit Jain
  • 2,523
  • 16
  • 33
0
votes
1 answer

missing parameter #2 in call error in CGRectIntersectsRect

I am writing a small game in swift, in which a boat has to go around obstacles. However, I keep getting this "missing argument for parameter #2 in call" error in CGRectInersectsRect. I have checked how to call it in the directory, and am calling it…
0
votes
1 answer

Prevent overlap of views

I have an array of subviews of my container view, added programmatically setting the frame manually. When the user select a filter I would like to zoom the selected views (matching the filter) increasing their size by 1.1 and maintaining the center…
LorenzOliveto
  • 7,796
  • 1
  • 20
  • 47
0
votes
0 answers

CGRectIntersection gives wrong frame

I am using CGRectIntersection to get the common visible frame availbale from subview UIView.I have an uiview shown as pullup view on screen(say screen1),where uiview(pullUpView) is added as subview to screen1.When anyone presses button on screen1 it…
deep
  • 99
  • 1
  • 2
  • 8
0
votes
1 answer

CGRect intersection from child to self

Question How to achieve an intersection of two sprites, when one is a child of self and the other is a child of a sprite? As their positions are completely different relevant to the comparisons between each other? Example; this is ran before each…
Daniel
  • 285
  • 3
  • 12
0
votes
1 answer

How to detect collision without physics

I want to detect when two bodies contact without using didBeginContact() function I try with CGRectIntersectsRect() without any effect. class GameScene: SKScene, SKPhysicsContactDelegate { // Player var _player = SKNode() var platform =…
grape1
  • 759
  • 2
  • 8
  • 19
0
votes
1 answer

Animating a UIImageView movement and then use CGRectIntersection

I have a UIImageView (stick) on top of my screen, and when the view appears, it animates a movement through the whole screen, until the end of it. In the middle of the screen there is a UIButton (hand) that I will press whenever the image that is…
Pedro Cabaço
  • 123
  • 12
0
votes
1 answer

Swift: How to tell which UIView(s) myView is intersecting with?

I have an array of 16 boxViews, which are present in random locations on my superview. I am dragging myView which is a special subView. I need to be able to tell which boxView(s), myView is intersecting with, at any given time. How do I do achieve…
Kashif
  • 4,642
  • 7
  • 44
  • 97
0
votes
1 answer

Error colliding Images method in Xcode/iOS

I am creating an iOS app with Xcode 6.1 using Objective C I am trying to create code to stop a moving object (Character) when hits another object. I have tried to do this using two methods but the object seem to be stopping at a different point to…
0
votes
0 answers

is there reasons why this code won't work on iphone and will on ipad?

the code is: if(CGRectIntersectsRect(icon1.frame, pig.frame) && icon1.image == [UIImage imageNamed:@"BerryBlueberryIphone.png"]){ } the code works in ipad but not iphone. spelling is correct for png file i can't seem to find out why it does…
0
votes
1 answer

CGRectIntersectsRect with UIImageView

I have this image in PNG format link. I inserted this image in my application through a imageView. All I'm trying to do is detect when another imageView slope that my candy cane image, for that, I used the code…
1
2