Может быть, на него уже отвечали, но я не смог его найти.Я создаю случайные UIImageView
экземпляры и добавляю их как подвиды к представлению viewController
.
Таким же образом я создаю UITapGestureRecognizer
экземпляры и добавляю их к UIImageView
экземплярам.Но тап не работает.
for _ in 0..<20 {
let iv = UIImageView()
iv.isUserInteractionEnabled = true
iv.frame.origin = CGPoint(x: randomXGenerator(), y: randomYGenerator())
iv.frame.size.width = randomGenerator()
iv.frame.size.height = iv.frame.width
iv.tintColor = UIColor.random() //To color the image inside the imageView
iv.image = bubble
view.addSubview(iv)
animateBubblesRandom(bubble: iv)
let tap = UITapGestureRecognizer(target: self, action: #selector(tappedOnBubble(object:)))
iv.addGestureRecognizer(tap)
}
А вот примеры TapGesture созданный:
<UITapGestureRecognizer: 0x6000012b5b00; state = Possible; view = <UIImageView 0x7fdf4e507660>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bed00; state = Possible; view = <UIImageView 0x7fdf4e70b0b0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf000; state = Possible; view = <UIImageView 0x7fdf4e6041f0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf100; state = Possible; view = <UIImageView 0x7fdf4e605fa0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf200; state = Possible; view = <UIImageView 0x7fdf4e6079c0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf300; state = Possible; view = <UIImageView 0x7fdf4e607d20>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf500; state = Possible; view = <UIImageView 0x7fdf4e608080>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf600; state = Possible; view = <UIImageView 0x7fdf4e6083e0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf700; state = Possible; view = <UIImageView 0x7fdf4e414520>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012b5f00; state = Possible; view = <UIImageView 0x7fdf4e414750>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012b6000; state = Possible; view = <UIImageView 0x7fdf4e70b2e0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bef00; state = Possible; view = <UIImageView 0x7fdf4e608b40>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bee00; state = Possible; view = <UIImageView 0x7fdf4e608ea0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf800; state = Possible; view = <UIImageView 0x7fdf4e609200>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf900; state = Possible; view = <UIImageView 0x7fdf4e6096b0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bfa00; state = Possible; view = <UIImageView 0x7fdf4e609a10>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bfb00; state = Possible; view = <UIImageView 0x7fdf4e609d70>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bfc00; state = Possible; view = <UIImageView 0x7fdf4e60a0d0>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bf400; state = Possible; view = <UIImageView 0x7fdf4e60a630>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
<UITapGestureRecognizer: 0x6000012bfd00; state = Possible; view = <UIImageView 0x7fdf4e60a990>; target= <(action=tappedOnBubbleWithObject:, target=<FloatingBubbles.ViewController 0x7fdf4e605440>)>>
Я не понимаю, почему это происходит.Пожалуйста, помогите!