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!= image
答案 0 :(得分:0)
如果此图像是个人图像视图,则只需轻触识别器并在触摸时调用操作即可。 How to assign an action for UIImageView object in Swift
答案 1 :(得分:0)
我认为你需要使用手势并设置图像userInteractionEnabled = true OBJ-C:
self.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];
tap.delegate= self;
[self.imageView addGestureRecognizer:tap];