我目前正在从我的服务器加载图像 . 图像很多,具体取决于它返回的图像数量 . 我已经能够成功显示这些图像,我可以向下滚动查看所有图像 . 现在我的问题是我想要一种方法,我可以点击特定的图像,我将能够缩放它 . 我在下面分享了我的代码:
//This line of code downloads the images and displays them
for obj in message{
if let dict = obj as? NSDictionary {
self.imagePath = dict.value(forKey: "path") as? String
let albumThumbnail = photos()
self.scrollView.addSubview(albumThumbnail)
albumThumbnail.translatesAutoresizingMaskIntoConstraints = false
albumThumbnail.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor).isActive = true
albumThumbnail.topAnchor.constraint(equalTo: self.scrollView.topAnchor, constant: contentViewTopConstraint).isActive = true
albumThumbnail.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor).isActive = true
albumThumbnail.heightAnchor.constraint(equalToConstant: 150).isActive = true
albumThumbnail.isUserInteractionEnabled = true
if let path = self.path{
if let imagePath = self.imagePath{
let strippedPath = path.replacingOccurrences(of: "\\", with: "")
let strippedImagePath = imagePath.replacingOccurrences(of: "\\", with: "")
albumThumbnail.sd_setImage(with: URL(string: "\(strippedPath)\(strippedImagePath)"), placeholderImage: UIImage(named: "default_profile"), options: [.continueInBackground, .progressiveDownload])
}
}
contentViewTopConstraint = contentViewTopConstraint + 170
}
}
1 回答
在图像点击时,U创建了滚动视图并将相应的图像添加为子视图,然后缩放就可以了 .
OUTPUT