【问题标题】:How do I apply touches to images, using Swift 3?如何使用 Swift 3 对图像应用触摸?
【发布时间】:2017-08-03 02:03:56
【问题描述】:

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touchesSet = touches as NSSet
    let touch = touchesSet.anyObject() as? UITouch
    let location = touch?.location(in: self.view)
    if touch!.view == bee1 {
        bee1?.center = location!
    } else if touch!.view == bee2 {
        bee2?.center = location!
    }
}

我需要使用 Swift 为 iOS 编写这个游戏;但我不知道如何使用 Swift 对图像应用触摸。到目前为止,我的尝试都失败了; touch!.view != 图片

【问题讨论】:

标签: ios swift


【解决方案1】:

如果这些图像是单独的图像视图,那么您可以简单地放置点击识别器并在您触摸它时调用操作。 How to assign an action for UIImageView object in Swift

【讨论】:

    【解决方案2】:

    我认为您需要使用手势并设置图像 userInteractionEnabled = true OBJ-C:

    self.imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];
    tap.delegate= self;
    [self.imageView addGestureRecognizer:tap];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多