0

我想让一个小的 image.png 在点击后消失。我是 swift 的新生儿,所以我在 Playground 上使用单一视图进行实验。任何人都可以帮助我吗?

4

1 回答 1

0

在创建 your_imageView 时添加此代码

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
your_imageView.isUserInteractionEnabled = true
your_imageView.addGestureRecognizer(tapGestureRecognizer)

func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
    let tappedImage = tapGestureRecognizer.view as! UIImageView

    tappedImage.isHidden = true
}
于 2019-10-19T10:23:16.433 回答