[ACCEPTED]-How to test if a point is in a view-cgpoint
Accepted answer
CGPoint
is no good with a reference point. If your 2 point is in window's coordinates then you 1 can get it using
CGPoint locationInView = [imageView convertPoint:point fromView:imageView.window];
if ( CGRectContainsPoint(imageView.bounds, locationInView) ) {
// Point lies inside the bounds.
}
You may also call pointInside:withEvent:
method
if ( [imageView pointInside:locationInView withEvent:nil] ) {
// Point lies inside the bounds
}
Tested in Swift 4
view.frame.contains(point)
0
if(CGRectContainsPoint([myView frame], point))
where point is your CGPoint and myView is 1 your UIImageView
I'll assume you have a full-screen window 5 (pretty reasonable, I think). Then you can 4 transform the point from the window's coordinate 3 space to the UIImageView's using:
CGPoint point = ...
UIWindow window = ...
UIImageView imageView = ...
CGPoint transformedPoint = [window convertPoint:point toView:imageView];
Then, you 2 can test if the point is in the image view's 1 frame as follows:
if(CGRectContainsPoint(imageView.frame, transformedPoint))
{
// do something interesting....
}
In Swift 3
let isPointInFrame = UIScreen.main.bounds.contains(newLocation)
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.