I'm sub classing an UIView to make its always floating on my app's screen. I'm using some method of NSResponder
like touchesMove
, touchesEnd
... to make this view can movable.
When I'm long press on this floating view another view called "Close View" will appear at bottom of screen.
Now I want whenever I'm drag & drop this floating view to Close View this will be remove from superview (this will look like Android launcher when you delete an app from screen). But I don't know how to calculate when 2 view was reached to remove the floating view.
Can someone help me to solve this problem? I've put a picture for imagination.
Update:
Here is my code:
- (BOOL)isTrashViewReached {
CGFloat distanceFromTrashView = sqrt(pow(self.center.x - self.trashView.center.x, 2) + pow(self.center.y - self.trashView.center.y, 2));
return distanceFromTrashView < self.bounds.size.width / 2;
}
-(void)updateTrashView {
UIColor *trashColor = self.isTrashViewReached ? [UIColor whiteColor] : [UIColor colorWithRed:174/255.0 green:0 blue:0 alpha:1];
[self.deleteButton setTitleColor:trashColor forState:UIControlStateNormal];
}