【问题标题】:swift xcode 8.0 - uiimageview drag inside uiviewswift xcode 8.0 - uiimageview 在 uiview 内拖动
【发布时间】:2016-11-25 18:07:55
【问题描述】:

我有两个 UIimageview 图像,它们可以使用 touchesBegan 和 touchesMoved 进行拖动,但是它们可以在屏幕上的任何位置拖动而没有任何限制。我试图将 UIimageview 限制为只能在 UIimage(特定区域)内拖动。

知道什么是最好的方法吗?

谢谢

【问题讨论】:

    标签: swift xcode uiimageview drag


    【解决方案1】:

    使用CGRectContainsPoint 限制区域。

    例如:

    let point = touch.location(in: self) // or elsewhere
    if CGRectContainsPoint(image.frame, point) {
      // could drag
    } else {
      // stop dragging 
    }
    

    【讨论】:

    • 你的意思是“touch.location”
    猜你喜欢
    • 1970-01-01
    • 2019-11-13
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    相关资源
    最近更新 更多