【发布时间】:2019-01-04 10:38:45
【问题描述】:
我想在点击屏幕时隐藏第三行的按钮,这个屏幕包含三行。我添加了触摸事件并尝试使用轻击手势,但只有当我点击第三行时,如果我点击其他行或点击屏幕的任何位置,按钮就会隐藏,没有任何反应。 主要问题是当我点击第三行然后按钮消失它应该被隐藏我们点击屏幕上的任何地方或点击任何单元格。 我正在使用 customView 在 tablewView 中显示该视图。 TableView 是单独的类,自定义视图是单独的类。我正在处理自定义视图类中的按钮。
请告诉我解决方案,这是我的代码
class MicTestView: UIView {
// MARK:-
// MARK:- Properties
// MARK:- IBOutlets
@IBOutlet weak var aidStatusImageView: UIImageView!
@IBOutlet weak var progressView: UIProgressView!
// MARK:- Class Properties
var micLocation : MicLocation = .bottom
let customInfoView = CustominfoView()
var customView = UIView()
// MARK:-
// MARK:- Methods
// MARK: UIView Methods
required init(coder aDecoder : NSCoder) {
super.init(coder :aDecoder)!
setup()
}
override init(frame : CGRect) {
super.init(frame: frame)
setup()
}
func setup() {
let view = loadViewFromXib()
view.frame = bounds
// view.autoresizingMask = UIViewAutoresizing.flexibleWidth | UIViewAutoresizing.flexibleHeight
addSubview(view)
progressView.progress = 0
progressView.transform = progressView.transform.scaledBy(x: 1, y: (view.superview?.bounds.height)!/2)
progressView.isHidden = true
view.isUserInteractionEnabled = true
}
func loadViewFromXib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "MicTestView", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
return view
}
// MARK:- IBActions
@IBAction func infoBtnpressed(_ sender: UIButton) {
customInfoView.isHidden = false
let customView = customInfoView
customView.frame = CGRect(x: ((window?.frame.origin.x)! + 60), y: ((window?.frame.origin.y)! + 300), width: 255, height: 200)
window?.addSubview(customView)
print("Pressed")
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
self.customInfoView.isHidden = true
}
}
// MARK: UIViewController overrides
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.infoBtn.isHidden = true
self.customInfoView.isHidden = true
startRecording()
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
//
}
【问题讨论】:
-
你可以使用协议委托来隐藏uitableview中的按钮。
-
请给我代码示例
标签: ios swift uiview xib custom-view