【发布时间】:2018-12-11 08:43:30
【问题描述】:
我有一个带有两张图片的UITableViewCell,我的目标是在用户长按时扩展这些图片。在最好的情况下,图像将覆盖整个屏幕,并带有一个小“x”或关闭的东西。
我在自定义UITableViewCell 中使用了以下函数,但图像只会扩大单元格的大小。我不知道如何在超级视图的整个 tableview/navBar/tabbar 上展开图像。
@objc func answerOneLongPress(_ sender: UILongPressGestureRecognizer) {
let imageView = sender.view as! UIImageView
let newImageView = UIImageView(image: imageView.image)
let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
newImageView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
self.addSubview(newImageView)
}
如果您需要更多信息,请告诉我。我觉得这应该发生在UITableViewController 而不是单元格中,但无法让它以这种方式工作。
【问题讨论】:
-
您可以在长按上使用可折叠的表格视图,只需重新加载特定部分
-
你能添加一个 gif 来显示发生了什么问题吗?
-
@RahulGUsai 是否愿意提供一些示例或更多信息?
-
self在您添加子视图的上下文中是什么?您需要将此子视图添加到视图控制器的视图或将事件添加到窗口UIApplication.shared.keyWindow。如果这是一个单元格,那么您的图像视图将被剪裁,甚至定位不正确。
标签: ios swift uitableview uiimageview