首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用UIPanGestureRecognizer检测重叠

用UIPanGestureRecognizer检测重叠
EN

Stack Overflow用户
提问于 2013-09-14 17:45:40
回答 1查看 104关注 0票数 0

我在UIButton上使用UIButton。我希望通过以下方式检测其中两种重叠的情况:

代码语言:javascript
复制
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上,这些UIButtondictionary的一部分。当用户在其中任何一个上发布时,程序必须识别其中哪一个重叠,以及来自dictionary的相对dictionary

我只能为CGRectContainsPoint指定一个按钮,我也不知道如何理解其中的一个按钮,并从dictionary获取key

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-14 17:59:19

试一试如下:

代码语言:javascript
复制
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
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18804626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档