本文介绍了iOS/Swift UIImageView (.jpg) 无法识别我的点击手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的代码块,可以在我的图像被点击时播放声音.但是,当我点击我的图像时,甚至无法识别点击.
I have a simple block of code to play a sound when my image gets tapped. However, when I tap my image, the tap isn't even recognized.
我相信这是真的,因为当点击图像时,handleTap 函数中的 println 不会打印任何内容.
I believe this to be true because println in the handleTap function doesn't print anything when the image is tapped.
谁能告诉我问题出在哪里?
Can anyone give me some insight as to where the problem might be?
var coinSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("wavSampleSound", ofType: "wav")!)
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
loadSound()
let gesture = UITapGestureRecognizer(target: self, action: "handleTap:")
gesture.delegate = self
myImage.addGestureRecognizer(gesture)
}
func loadSound() {
audioPlayer = AVAudioPlayer(contentsOfURL: coinSound, error: nil)
audioPlayer.prepareToPlay()
}
func handleTap(gesture: UITapGestureRecognizer) {
let playsSound = self.audioPlayer.play()
println("(playsSound)")
}
@IBOutlet weak var myImage: UIImageView!
}
推荐答案
注意UIImageView
的userInteractionEnabled
默认设置为false
.您想将其设置为 true
.
Note that the default setting of the userInteractionEnabled
of UIImageView
is false
. You want to set it to true
.
这篇关于iOS/Swift UIImageView (.jpg) 无法识别我的点击手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!