ytyubox / YuBlog

這是用來記錄的Blog,紀錄內容在 Issues 頁面中。
0 stars 0 forks source link

20190309 對於addTarget的雷區 #5

Open ytyubox opened 5 years ago

ytyubox commented 5 years ago

Button在指定Target時有3個雷區

  1. addTarget before init
  2. Button on scrollViiew
  3. Button on a !!!userInteractable superView

A1:

lazy var button: UIButton = {
    let button = UIButton()
    button.addTarget(self,#selector(aSelector), .touchUpInside)
    return button
}()

A2:

scrollView.isExclusiveTouch = true
scrollView.delaysContentTouches = false

A3:

button.superView.isUserInteractionEnabled = true