UIImageView识别器

在我的应用程序,我有一个大UIImageView和其他5个较小。

我的意图是将选定的小图像的内容复制到最大的一个。 也获取所选图像的名称并用UILabel显示。

将UButtons更换为小图像可能更容易,并显示图像作为背景?

我会为每个imageView添加一个gestureRecognizer。 由gestureRecognizer调用的函数将改变“大select器视图”上的图像。 没有内置的方式来获取用户select的图像名称。 如果你真的需要这个,那么你可以sublcass UIImageView并添加一个fileName属性。

@IBOutlet var imageView: UIImageView! @IBOutlet var bigPickerImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // create tap gesture recognizer let tapGesture = UITapGestureRecognizer(target: self, action: "tapGesture:") // add it to the image view; imageView.addGestureRecognizer(tapGesture) // make sure imageView can be interacted with by user imageView.userInteractionEnabled = true } func tapGesture(gesture: UIGestureRecognizer) { // if the tapped view is a UIImageView then set it to imageview if let imageView = gesture.view as? UIImageView { // if you subclass UIImageView, then change "UIImageView" to your subclass // change the image on the bigPickerImageView bigPickerImageView.image = imageView.image // if you subclass UIImageView, then you could get the filename here. } }