0

enter image description here

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!
    }
}

I need code this game for iOS, using Swift; but I don't know how to apply touches to images, using Swift. My attempts thus far have failed; touch!.view != image

Ignatius
  • 1,167
  • 2
  • 21
  • 30

2 Answers2

0

If this images are indiviudal image views, then you can simply put tap recognizer and call action when you touch it. How to assign an action for UIImageView object in Swift

Im Batman
  • 1,842
  • 1
  • 31
  • 48
0

I think that you need to use gesture and set the image userInteractionEnabled = true OBJ-C:

self.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];
tap.delegate= self;
[self.imageView addGestureRecognizer:tap];
Ringo
  • 1,173
  • 1
  • 12
  • 25