【问题标题】:How do I drag and drop a label to autocomplete textfield?如何将标签拖放到自动完成文本字段?
【发布时间】:2015-04-19 03:15:09
【问题描述】:

我想拖放标签或自动完成 UITextfield 的东西。例如,如果我有一个空文本字段,并且我在文本字段顶部拖动带有文本“hello world”的标签,则文本字段将具有“hello world”作为其文本。有谁知道我该怎么做? UILabel 是最好的选择吗?或者也许 UIButton 可以工作?

【问题讨论】:

  • 你有没有尝试过自己解决这个问题?这需要几个步骤。你不知道怎么做?你知道如何拖动视图吗?您知道如何判断一个视图何时与另一个视图重叠(在其之上)吗?
  • @rdelmar 我不太确定我应该采取的步骤。现在,我有一个常规的 UITextfield 和一个标签,可以在屏幕上拖动/移动。你建议我下一步做什么?
  • 结束拖动时,使用CGRectIntersectsRect检查标签是否与文本字段重叠。如果是,则从标签中获取字符串,并将该字符串设置在文本字段中。
  • @rdelmar 想通了!我最终使用了 CGRectContainsPoint。非常感谢!
  • @laura 你解决问题了吗。如果有,您可以将答案标记为已接受并投票

标签: ios objective-c iphone xcode6


【解决方案1】:

您最好先阅读有关 IOS 开发的教程。跟着教程走

在本站http://www.appcoda.com/ios-programming-course/

对于您的问题研究,请先访问以下链接,然后再提出问题

http://www.appcoda.com/hello-world-build-your-first-iphone-app/
http://www.appcoda.com/ios-programming-basic-how-does-the-hello-world-app-work/

【讨论】:

    【解决方案2】:

    试试这个

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
       //get position
       // get label on that position
       [label removeFromSuperView];
       newLabel = [[UILabel alloc] init]; 
       [self.view addSubView:newLabel]; //positioned at label
    }
    
    touchesMoved {
       //getPosition
       newLabel.position = position;
    }
    
    touchesEnded {
       //getPosition.
       self.view.subviews; // loop and find which view has the position.
    
       UILabel *finalLabel = [[UILabel alloc] init];
       finalLabel.center = newLabel.center;
    
       [newLabel removeFromSuperView];
    
       [viewToBeDroppedOn addSubview:finalLabel];
    }
    

    也可以查看本教程Drag & Drop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      相关资源
      最近更新 更多