http://pastebin.com/MgQ7wx3g編程按鈕不起作用
所以目前我正在試圖讓這個按鈕的工作叫做Play按鈕
let playButton: UIButton = {
let button = UIButton()
let image = UIImage(named: "VideoIcon.png") as UIImage?
button.backgroundImage(for: .normal)
button.addTarget(self, action: #selector(pressBackButton(button:)), for: .touchUpInside)
button.setImage(image, for: .normal)
return button
}()
func pressBackButton(button: UIButton) {
print("test")
if let playVideoButtonURL = post?.videourl {
let player = AVPlayer(url: playVideoButtonURL as URL)
let playerLayer = AVPlayerLayer(player:player)
playerLayer.frame = CGRect(x: 100, y: 200, width: 100, height: 100)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
self.layer.addSublayer(playerLayer)
player.play()
}
}
當我點擊它沒有任何反應,即使在視頻編碼是錯誤的它仍然應該打印測試。它在啓動時不會給我帶來任何錯誤。粘貼箱有我的完整代碼。
所以我試圖改變addSubview到contentView.addsubview按鈕仍然顯示,但是當我在它 – Tim
@Tim我覺得還是點擊沒有任何反應它的一些約束問題。首先,我只設置了水平約束並忘記了垂直約束,並且它不工作。 –
啊好吧。然後我會研究它。謝謝你的幫助! – Tim