iOS/Swift UIImageView (.jpg) 无法识别我的点击手势?

iOS/Swift UIImageView (.jpg) not recognizing my tap gesture?(iOS/Swift UIImageView (.jpg) 无法识别我的点击手势?)
本文介绍了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!

}

推荐答案

注意UIImageViewuserInteractionEnabled默认设置为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) 无法识别我的点击手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)