Swift实战-豆瓣电台(九)简单手势控制暂停播放
收起
这节我们主要讲UITapGestureRecognizer和MPMoviePlayerController
知识点UITapGestureRecognizer关联storyboard上的UITapGestureRecognizer@IBOutlet
var tap:UITapGestureRecognizer=nil
//注意要设置为nil增加手势识别addGestureRecognizer(tap)
移除手势识别removeGestureRecognizer(tap)
关联Action@IBAction func onTap(recognizer: UITapGestureRecognizer)
通过recognizer.view可以判断点击了哪个组件
@IBAction func onTap(recognizer: UITapGestureRecognizer){
if recognizer.view==btnPlay {btnPlay.hidden=
trueaudioPlayer.play()btnPlay.removeGestureRecognizer(tap)iv.addGestureRecognizer(tap)}
else if recognizer.view==iv {btnPlay.hidden=
falseaudioPlayer.pause()btnPlay.addGestureRecognizer(tap)iv.removeGestureRecognizer(tap)}}
MPMoviePlayerController播放play()
暂停pause()