我有一个UICollectionView,它基本上是一个聊天日志。我在一些单元格中有一个imageView,并添加了在点击时将图像扩展到全屏的功能。
///
ChatLogMessageCell.swift
/**
*
* I add the target to the UIButton with an image as a background
*/
messageImage.addTarget(self, action: #selector(fullscreenImage), for: .touchUpInside)
/*
* Full screen code
*/
@objc func fullscreenImage() {
if let chatlog = parentViewController as? ChatLogController {
let imageScroll = UIScrollView()
imageScroll.delegate = self
imageScroll.minimumZoomScale = 1.0
imageScroll.maximumZoomScale = 5.0
imageScroll.frame = UIScreen.main.bounds
let newImageView = UIImageView(image: messageImage.backgroundImage(for: .normal))
newImageView.frame = UIScreen.main.bounds
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
newImageView.isUserInteractionEnabled = true
imageScroll.addSubview(newImageView)
chatlog.view.addSubview(imageScroll)
chatlog.navigationController?.isNavigationBarHidden = true
chatlog.tabBarController?.tabBar.isHidden = true
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
newImageView.addGestureRecognizer(tap)
}
}
@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
if let chatlog = parentViewController as? ChatLogController {
chatlog.navigationController?.isNavigationBarHidden = false
chatlog.tabBarController?.tabBar.isHidden = false
sender.view?.removeFromSuperview()
}
}
删除全屏图像后,ChatLogController不再可交互。我无法在图像上滚动或重新进入全屏模式。这里缺少什么?我只想关闭全屏图像,允许用户选择另一个图像或只是滚动信息。
最佳答案
在这里删除imageView
sender.view?.removeFromSuperview()
当你需要像
sender.view?.superview?.removeFromSuperview()
关于swift - removeFromSuperView禁用交互,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56486009/