我在UIButton上使用UIButton。我希望通过以下方式检测其中两种重叠的情况:
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded ||
[(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateCancelled ||
[(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateFailed) {
CGPoint fingerPoint;
for(id key in BluetoothDeviceDictionary) {
UIButton* btn = [BluetoothDeviceDictionary objectForKey:key];
fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:btn.superview];
}
//BLUETOOTH SHARING
if (CGRectContainsPoint(All buttons from dictionary.frame, fingerPoint)) {
for the UIButton that has been overlapped do...基本上正在发生的是,用户将一个UIButton拖到屏幕上的一系列UIButton中的任何其他UIButton上,这些UIButton是dictionary的一部分。当用户在其中任何一个上发布时,程序必须识别其中哪一个重叠,以及来自dictionary的相对dictionary。
我只能为CGRectContainsPoint指定一个按钮,我也不知道如何理解其中的一个按钮,并从dictionary获取key。
发布于 2013-09-14 17:59:19
试一试如下:
UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)sender;
if(gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateCancelled ||
gesture.state == UIGestureRecognizerStateFailed) {
CGPoint dropPoint = [gesture locationInView:gesture.view.superview];
for(id key in BluetoothDeviceDictionary) {
UIButton* btn = [BluetoothDeviceDictionary objectForKey:key];
if (CGRectContainsPoint(btw.frame, dropPoint)) {
// overlap - do something...
// maybe continue or return (if the loop shouldn't continue to test the other buttons
}
}https://stackoverflow.com/questions/18804626
复制相似问题