繁体   English   中英

在GooeySlideMenu上添加时,不会调用UITableView委托方法

[英]UITableView delegate methods are not called when added on GooeySlideMenu

我想在UIView的顶部添加UITableView,UIView是GooeySlideMenu的子类。 如git中所示的示例,我创建了UITableView而不是UIButtons,但是未调用委托方法。

下面是我的代码供参考:

class GooeySlideMenu: UIView {

fileprivate var _option: MenuOptions
fileprivate var keyWindow: UIWindow?
fileprivate var blurView: UIVisualEffectView!
fileprivate var helperSideView: UIView!
fileprivate var helperCenterView: UIView!

fileprivate var diff: CGFloat = 0.0
fileprivate var triggered: Bool = false
fileprivate var displayLink: CADisplayLink?
fileprivate var animationCount: Int = 0
fileprivate   var myTableView: tableViewCustomClass  =  tableViewCustomClass()


init(options: MenuOptions) {
    _option = options
    if let kWindow = UIApplication.shared.keyWindow{
        keyWindow = kWindow
        let frame = CGRect(
            x: -kWindow.frame.size.width/2 - options.menuBlankWidth,
            y: 0,
            width: kWindow.frame.size.width/2 + options.menuBlankWidth,
            height: kWindow.frame.size.height)
        super.init(frame:frame)
    } else {
        super.init(frame:CGRect.zero)
    }
    setUpViews()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func draw(_ rect: CGRect) {
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 0, y: 0))
    path.addLine(to: CGPoint(x: frame.width-_option.menuBlankWidth, y: 0))
    path.addQuadCurve(to: CGPoint(x: frame.width-_option.menuBlankWidth, y: frame.height), controlPoint: CGPoint(x: frame.width-_option.menuBlankWidth+diff, y: frame.height/2))
    path.addLine(to: CGPoint(x: 0, y: frame.height))
    path.close()

    let context = UIGraphicsGetCurrentContext()
    context?.addPath(path.cgPath)
    _option.menuColor.set()
    context?.fillPath()
}

func trigger() {
    if !triggered {
        if let keyWindow = keyWindow {
            keyWindow.insertSubview(blurView, belowSubview: self)
            UIView.animate(withDuration: 0.3, animations: { [weak self] () -> Void in
                self?.frame = CGRect(
                    x: 0,
                    y: 0,
                    width: keyWindow.frame.size.width/2 + (self?._option.menuBlankWidth)!,
                    height: keyWindow.frame.size.height)
            })

            beforeAnimation()
            UIView.animate(withDuration: 0.7, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.9, options: [.beginFromCurrentState,.allowUserInteraction], animations: { [weak self] () -> Void in
                self?.helperSideView.center = CGPoint(x: keyWindow.center.x, y: (self?.helperSideView.frame.size.height)!/2);
                }, completion: { [weak self] (finish) -> Void in
                    self?.finishAnimation()
                })

            UIView.animate(withDuration: 0.3, animations: { [weak self] () -> Void in
                self?.blurView.alpha = 1.0
            })

            beforeAnimation()
            UIView.animate(withDuration: 0.7, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: [.beginFromCurrentState,.allowUserInteraction], animations: { [weak self] () -> Void in
                self?.helperCenterView.center = keyWindow.center
                }, completion: { [weak self] (finished) -> Void in
                    if finished {
                        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(GooeySlideMenu.tapToUntrigger))
                        self?.blurView.addGestureRecognizer(tapGesture)
                        self?.finishAnimation()
                    }
            })
          //  animateButtons()
            myTableView.reloadData()
            triggered = true
        }
    } else {
        tapToUntrigger()
    }
}

}

 extension GooeySlideMenu {

fileprivate func setUpViews() {
    if let keyWindow = keyWindow {
        blurView = UIVisualEffectView(effect: UIBlurEffect(style: _option.blurStyle))
        blurView.frame = keyWindow.frame
        blurView.alpha = 0.0

        helperSideView = UIView(frame: CGRect(x: -40, y: 0, width: 40, height: 40))
        helperSideView.backgroundColor = UIColor.red
        helperSideView.isHidden = true
        keyWindow.addSubview(helperSideView)

        helperCenterView = UIView(frame: CGRect(x: -40, y: keyWindow.frame.height/2 - 20, width: 40, height: 40))
        helperCenterView.backgroundColor = UIColor.yellow
        helperCenterView.isHidden = true
        keyWindow.addSubview(helperCenterView)

        backgroundColor = UIColor.clear
        keyWindow.insertSubview(self, belowSubview: helperSideView)

        addUItableView()
      //  addButton()
    }
}

fileprivate func addUItableView(){



    myTableView.frame = CGRect(x: 0, y: 20, width: 300, height: 200)


    myTableView.backgroundColor = UIColor.white
    myTableView.delegate = tableViewCustomClass() as? UITableViewDelegate
    myTableView.dataSource = tableViewCustomClass() as? UITableViewDataSource
    addSubview(myTableView)

}

您需要在tableViewCustomClass的类(而不是GooeySlideMenu class)上声明tableview的委托。

在tableViewCustomClass中

tableViewCustomClass的Initializer方法中的self.delegate = self

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM