UIImageView 识别器 [英] UIImageView Recognizer

查看:25
本文介绍了UIImageView 识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my app I have a big UIImageView and other 5 smaller.

我的意图是将选中的小Image的内容复制到最大的.还可以获取所选图像的名称并使用 UILabel 显示.

My intention is to copy the content of the selected small Image to the biggest one. Also to get the name of the chosen image and show with a UILabel.

用 UIButtons 替换小图像并将图像显示为背景会更容易吗?

Will be maybe easier to replace the small images by UIButtons and display the image as a background?

推荐答案

我会为每个 imageView 添加一个gestureRecognizer.然后由gestureRecognizer 调用的函数将更改大选择器视图"上的图像.没有内置方法可以获取用户选择的图像名称.如果你真的需要这个,那么你可以子类 UIImageView 并添加一个 fileName 属性.

I would add a gestureRecognizer to each imageView. The function called by the gestureRecognizer would then change the image on the "big picker view". There is no built-in way to get the image name that the user chose. If you really needed this, then you could sublcass UIImageView and add a fileName property.

@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.
    }
}

这篇关于UIImageView 识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆