Subviews’ tapgesture can sometimes be recognized and sometimes cannot be recognized.

  ios, question

I set click events for all sub-views, but these view click events can sometimes respond and sometimes not

import UIKit

class BottomContainerView: UIView {
    
    var clickItemProtocol : ClickItemProtocol?
    
    override func layoutSubviews() {
        
        let viewWidth = self.bounds.width
        let subDeviceWidth = (viewWidth-12)/3
        var startXpos : CGFloat =  2
        var startXXpos : CGFloat  =  2
        for i in 0 ..< subviews.count{
            let view = subviews[i]
            let uiTapGesture = UITapGestureRecognizer(target: self, action: "click:")
            uiTapGesture.numberOfTapsRequired = i
            view.userInteractionEnabled = true
            view.addGestureRecognizer(uiTapGesture)
            if i < 3{
                view.frame.origin.x = startXpos
                view.frame.origin.y = 2
                view.bounds.size.width = subDeviceWidth
                view.bounds.size.height = subDeviceWidth
                startXpos = startXpos 加 4 加 subDeviceWidth
            }else if i>=3 && i < 6{
                view.frame.origin.x = startXXpos
                view.frame.origin.y = 6 加 subDeviceWidth
                view.bounds.size.width = subDeviceWidth
                view.bounds.size.height = subDeviceWidth
                startXXpos = startXXpos 加 4 加 subDeviceWidth
            }
        }
    }
    
    func setOnItemClickProtocol(clickItemProtocol : ClickItemProtocol){
        self.clickItemProtocol = clickItemProtocol
    }
    
    func click(sender:UITapGestureRecognizer){
        print("click")
        self.clickItemProtocol?.onItemClick(sender.numberOfTapsRequired)
    }

}

protocol ClickItemProtocol{
    func onItemClick(position : Int)
}
uiTapGesture.numberOfTapsRequired = i

Are you sure you need n consecutive points before responding?