ios - UIview下的UIButton无法触摸

标签 ios swift uiview uibutton

我在 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/

相关文章:

ios - Swift:继承 UITextView 或 UICollectionView 并正确初始化

ios - CoreData 合并冲突显示托管对象版本更改而不是数据

ios - 访问 Swift 中的其他函数

ios - 如何从两个不同的 IOC 容器解析单例实例

iphone - UISegmentedcontrol 在 UITabbarcontroller 中切换 View

swift - 为什么我的场景在 swift sprite kit 中不会改变?

ios - 在 Swift 中以编程方式设置 UI 约束(UIView 中的图像和 stackView)

ios - 新的 Apple SDK 是否会修补以前的版本?

C++ 生成器 10 CoreFondation.h(12) : 'Stdarg.h' file not found

ios - SWIFT:计算 tableView 的 numberOfRowsInSection 时数组索引超出范围