Is there a way to verify if a CGPoint
is inside a specific CGRect
.
At example: I'm dragging an UIImageView
and I want to verify if its central point CGPoint
is inside another UIImageView
how can I do?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
In Swift that would look like this:
Swift 3 version:
Link to documentation . Please remember to check containment if both are in the same coordinate system if not then conversions are required (some example)
Swift
Use
CGRect.contains(_: CGPoint)
:Objective-C
Use
CGRectContainsPoint()
:bool CGRectContainsPoint(CGRect rect, CGPoint point);
Parameters
rect
The rectangle to examine.point
The point to examine. Return Value true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false.A point is considered inside the rectangle if its coordinates lie inside the rectangle or on the minimum X or minimum Y edge.
In objective c you can use CGRectContainsPoint(yourview.frame, touchpoint)
In swift 3 yourview.frame.contains(touchpoint)
It is so simple,you can use following method to do this kind of work:-
In your case,you can pass imagView.center as point and another imagView.frame as rect in about method.
You can also use this method in bellow UITouch Method :
In swift you can do it like this:
"frame" is a CGRect and "point" is a CGPoint