簡體   English   中英

如何使用Swift 3將觸摸應用於圖像?

[英]How do I apply touches to images, using Swift 3?

在此處輸入圖片說明

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將觸摸應用於圖像。 到目前為止,我的嘗試失敗了。 觸摸!查看圖像

如果這些圖像是單獨的圖像視圖,那么您只需放置輕拍識別器並在觸摸它時調用操作即可。 如何在Swift中為UIImageView對象分配動作

我認為您需要使用手勢並設置圖像userInteractionEnabled = true OBJ-C:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM