According to my requirement i need to check UIView
are placed inside of UIImage
portion or not.Suppose i have UIImage
of human with cap, here i need to check my view placed inside of cap portion or not.
Could you please guide me to achieve following requirement.
---------------------------------
| |
| UIImage |
| -------------------------- |
| | Image portion | |
| | ------ | |
| | | view | | |
| | ------ | |
| | | |
| -------------------------- |
| |
| |
--------------------------------
You could use the method contains(_:)
or intersects(_:)
of CGRect
.
Your code will look something like
let imagePortionFrame = CGRect(....) // some rect based on your image view
imagePortionFrame.contains(view.frame)
You just need to make sure that the coordinates of imagePortionFrame
and view.frame
are expressed using the same coordinate system; if not you could use the method convert(_:to:)
Reference:
contains
intersect
convert
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With