1 iphone uiimageview uigesturerecognizer ios swift
当我的图像被点击时,我有一个简单的代码块来播放声音.但是,当我点按图像时,甚至无法识别水龙头.
我相信这是真的,因为handleTap函数中的println在点击图像时不会打印任何内容.
谁能给我一些关于问题可能在哪里的见解?
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!
Run Code Online (Sandbox Code Playgroud)
}
归档时间: |
|
查看次数: |
520 次 |
最近记录: |