2017-08-17 13 views
0

私はIBActionにリンクされたデフォルトのUIButtonを持っています(内部をタッチアップ)。これは正常に動作するので、接続が正常であることがわかります。 UIButtonクラスをカスタムボタンに変更すると、IBActionはもうトリガーされません。以下は私のカスタムUIButtonのコードです。これがなぜ起こっているのか?カスタムUIButton - IBActionが機能しない

import UIKit 

@IBDesignable 
class PrimaryButton: UIButton { 

    override init(frame: CGRect) { 
     super.init(frame: frame) 
     initView() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
     initView() 
    } 


    private func initView() { 
     let view = viewFromNibForClass() 

     view.frame = bounds 

     view.autoresizingMask = [ 
      UIViewAutoresizing.flexibleWidth, 
      UIViewAutoresizing.flexibleHeight 
     ] 

     addSubview(view) 
    } 

    private func viewFromNibForClass() -> UIView { 
     let bundle = Bundle(for: type(of: self)) 
     let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle) 
     let view = nib.instantiate(withOwner: self, options: nil).first as! UIView 

     return view 
    } 
} 

答えて

1

ボタンに触れないためコードが機能しません。すべてのタッチは、追加した一番上のカスタムビューに送信されます。

view.userInteractionEnabled = falseを設定すると、タッチに透明になります。

0

カスタムボタンは追加したビューの対象です。

関連する問題