2017-04-24 12 views
0

GooeySlideMenuのサブクラスであるUIViewの上にUITableViewを追加したいとします。 gitの例のように、UIButtonの代わりにUITableViewを作成しましたが、デリゲートメソッドは呼び出されません。あなたが代わりにGooeySlideMenuクラスのtableViewCustomClassのクラスで宣言テーブルビューのデリゲートに必要GooeySlideMenuに追加すると、UITableViewデリゲートメソッドが呼び出されない

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) 

} 
+0

tableViewCustomClassで

self.delegate =自己は何としてmyTableView.delegate = tableViewCustomClass()を使用するのですか? UITableViewDelegate – KKRocks

+0

私が前に書いたデリゲートメソッドを呼び出すには何か間違っていますか? – user2931321

+0

ここでtableviewのデリゲートメソッドが宣言されていますか? – KKRocks

答えて

1

は下記参照のための私のコードです。 tableViewCustomClassの初期化子方法

関連する問題