iOS/Swift UIImageView (.jpg) not recognizing my tap gesture?(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) 无法识别我的点击手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS/Swift UIImageView (.jpg) 无法识别我的点击手势?


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01