【问题标题】:Custom view scrolls inside a scroll view自定义视图在滚动视图内滚动
【发布时间】:2023-03-08 17:27:02
【问题描述】:

我创建了一个名为SignView 的自定义视图,并添加到另一个名为mainSignView 的自定义视图中,该视图位于一个名为getFormView 的滚动视图中,但是当我在signView 上签名时,它会滚动,我无法做任何手势来帮助我克服请这个!

这就是我所拥有的

    @objc func pressedSignViewAction(_ sender: UILabel) {

    self.signViewElement = "signView1"
    uniY += 60
    mainSignView = UIView(frame: CGRect(x: 20, y: uniY, width: 250, height: 250))
    mySignViewName = UILabel(frame: CGRect(x: 20, y: 10, width: 200, height: 30))
    let signLabel = UILabel(frame: CGRect(x: 20, y: 50, width: 200, height: 30))
    signView  = YPDrawSignatureView(frame: CGRect(x: 10, y: 90, width: 230, height: 100))
    signView.backgroundColor = .white

    signLabel.text = "Signature"
    mainSignView.backgroundColor = .green

    mySignViewName.text = self.signViewNameFD
    self.signViewNameElement = self.signViewNameFD

   cancelButton = UIButton(frame : CGRect(x: 20, y: 200, width: 100, height: 25))
    cancelButton.addTarget(self, action: #selector(pressedSignClearAction(_:)), for: .touchUpInside)
    cancelButton.setTitle("Clear",for: .normal)
    cancelButton.setTitleColor(UIColor.red, for: .normal)


    uniY += 170


    self.view.addSubview(getFormView)
    //self.getFormView.addSubview(signLabel)
    self.getFormView.addSubview(mainSignView)
    self.mainSignView.addSubview(signLabel)
    self.mainSignView.addSubview(signView)
    self.mainSignView.addSubview(mySignViewName)
    self.mainSignView.addSubview(cancelButton)

    self.enterSignViewTitle()
    self.updateScrollY()
}

@objc func pressedSignClearAction(_ sender: UIButton) {

self.signView.clear()

}

【问题讨论】:

    标签: ios swift uiview uiscrollview


    【解决方案1】:

    来自YPDrawSignatureView Documentation

    // MARK: - Delegate Methods
    
    // The delegate functions gives feedback to the instanciating class. All functions are optional,
    // meaning you just implement the one you need.
    
    // didStart() is called right after the first touch is registered in the view.
    // For example, this can be used if the view is embedded in a scroll view, temporary
    // stopping it from scrolling while signing.
    func didStart() {
        print("Started Drawing")
        yourScroll.isScrollEnabled = false
    }
    
    // didFinish() is called rigth after the last touch of a gesture is registered in the view.
    // Can be used to enable scrolling in a scroll view if it has previous been disabled.
    func didFinish() {
        print("Finished Drawing")
        yourScroll.isScrollEnabled = true
    }
    

    【讨论】:

    • 您是否已将 YPSignatureDelegate 添加到您的 UIViewController,并为您的 signView 设置它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    相关资源
    最近更新 更多