To achieve the same in quick accordance with the accepted answer, here is the function. Ready code. Just copy and use it according to the steps. By the way, I am using Xcode 7.2 with Swift 2.1.1.
func checkViewIsInterSecting(viewToCheck: UIView) -> Bool{ let allSubViews = self.view!.subviews //Creating an array of all the subviews present in the superview. for viewS in allSubViews{ //Running the loop through the subviews array if (!(viewToCheck .isEqual(viewS))){ //Checking the view is equal to view to check or not if(CGRectIntersectsRect(viewToCheck.frame, viewS.frame)){ //Checking the view is intersecting with other or not return true //If intersected then return true } } } return false //If not intersected then return false }
Now call this function according to the following -
let viewInterSected = self.checkViewIsInterSecting(newTwoPersonTable) //It will give the bool value as true/false. Now use this as per your need
Thanks.
Hope this helps.
source share