在我的应用程序中,我有一个很大的UIImageView和其他5个较小的。
我的目的是将所选小图像的内容复制到最大的图像。还要获取所选图像的名称并使用UILabel进行显示。
用UIButtons替换小图像可能更容易,并将图像显示为背景?
答案 0 :(得分:4)
我会为每个imageView添加一个gestureRecognizer。之后,gestureRecognizer调用的函数将更改“大选择器视图”上的图像。没有内置方法来获取用户选择的图像名称。如果你真的需要这个,那么你可以升级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.
}
}