我在 UIView
下添加了 UIButton
但我添加了它无法触及的操作目标:
这是我的代码:
testview.swift
import UIKit
class testview: UIView {
@IBOutlet var comment:UIButton!
}
在viewconrtroller.swift
class ViewController:UIViewController,UIScrollViewDelegate{
@IBOutlet var inner:testview!
@IBOutlet var sc: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
sc.delegate = self
sc.isScrollEnabled = true
sc.delaysContentTouches = false
sc.contentSize = CGSize(width:320, height:1805)
inner.isUserInteractionEnabled = true
inner.isExclusiveTouch = true
inner.comment.isEnabled = true
inner.comment.addTarget(ViewController(), action: #selector(touched(_:)), for: .touchUpInside)
}
@IBAction func fullcomment(_ sender: UIButton) {
print("touched")
}
最佳答案
改变
inner.comment.addTarget(ViewController(), action: #selector(touched(_:)), for: .touchUpInside)
到
inner.comment.addTarget(self, action: #selector(fullcomment(_:)), forControlEvents: .TouchUpInside)
关于ios - UIview下的UIButton无法触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40234379/