我有以下问题。我在视图控制器中有大约10个不同的图像。现在我希望图像在点击时切换到全屏。我已经将allow user interaction选项设置为yes,并输入我在本网站上找到的以下代码:
import UIKit
class ImageViewController: UIViewController {
@IBAction func imageTapped(sender: UITapGestureRecognizer) {
let imageView = sender.view as! UIImageView
let newImageView = UIImageView(image: imageView.image)
newImageView.frame = self.view.frame
newImageView.backgroundColor = .blackColor()
newImageView.contentMode = .ScaleAspectFit
newImageView.userInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: "dismissFullscreenImage:")
newImageView.addGestureRecognizer(tap)
self.view.addSubview(newImageView)
}
func dismissFullscreenImage(sender: UITapGestureRecognizer) {
sender.view?.removeFromSuperview()
}
有谁知道为什么我的图片无法点播并转为全屏?
答案 0 :(得分:0)
确保图像视图都具有userInteractionEnabled = YES和 以下是您在此处尝试做的示例https://github.com/abhinavsingh77/ImagePreview