title: How to use UICollectionView with several buttons inside
body: <p>I have this pet project with a bunch of buttons inside, every button has an action on touchDown and its working without issues. But the problem is when I have 10x10 or more and I drag the UICollectionView, such buttons can't be touched anymore! They won't respond to any event and I can't realise whats happening.</p>
  
  <p>See a screenshot
  <a href="https://i.stack.imgur.com/4LG4K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4LG4K.png" alt="enter image description here"></a></p>
  
  <p>This game must have several cells, it can be huge but I don't think 100x100 is huge enough for any modern IOS cellphone, its not having more than 60mb ram memory usage so I don't think its the problem.
  See some of my code snippets.</p>
  
  <p>My view controller</p>
  
  <pre><code>@IBOutlet weak var myView: UICollectionView!
  
  let squareButton: SquareButton = buttonSquare(row: row, col: col, frameWidth: self.myView.frame.width, worldSize: worldSize).squareButton
                      squareButton.addTarget(self, action: #selector(ViewController.squareButtonPressed(_:)), for: .touchUpInside)
                      squareButton.tag = buttonCount
                      self.myView.addSubview(squareButton)
  </code></pre>
  
  <p>My struct to build those buttons</p>
  
  <pre><code>struct buttonSquare {
          var row: Int
          var col: Int
          var frameWidth: CGFloat
          var worldSize: Int
          var squareButton: SquareButton {
              get {
                  let square = Square(row: row, col: col)
                  let squareSize:CGFloat =  frameWidth / 20.0 //CGFloat(worldSize)
                  let squareButton = SquareButton(squareModel: square, squareSize: squareSize, squareMargin1: 1.0);
                  squareButton.setTitleColor(UIColor.darkGray, for: .normal)
                  // squareButton.addTarget(self, action: #selector(ViewController.squareButtonPressed(_:)), for: .touchDown)
                  return squareButton
              }
          }
      }
  </code></pre>
  
  <p>My button code</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class SquareButton : UIButton {
  
      var squareSize:CGFloat
      var squareMargin:CGFloat
      var square:Square
  
      init(squareModel:Square, squareSize:CGFloat, squareMargin1:CGFloat) {
          self.square = squareModel
          self.squareSize = squareSize
          self.squareMargin = squareMargin1
          let x = CGFloat(self.square.col) * (squareSize + squareMargin1)
          let y = CGFloat(self.square.row) * (squareSize + squareMargin1)
          let squareFrame = CGRect(x:x, y:y, width:squareSize, height:squareSize)
          super.init(frame: squareFrame)
          self.backgroundColor = squareModel.live ? .black : .white
          self.layer.borderWidth = 0.8
          self.layer.borderColor = UIColor.black.cgColor
      }
  
      override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          super.touchesMoved(touches, with: event)
      }
  
      func change(_ state:Bool) {
          self.backgroundColor = state ? .black : .white
          square.live = state
      }
  
      required init(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4LG4K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4LG4K.png" alt="I can&#39;t click on buttons beyond that position"></a></p>
  
  <p>Xcode 9, swift 4
  Thank you.</p>