gpt4 book ai didi

ios - 如何全屏显示图像并通过类似于 Apple Photos 的滑动关闭

转载 作者:行者123 更新时间:2023-11-28 11:37:58 25 4
gpt4 key购买 nike

如何实现 Apple Photos 的全屏图像和关闭图像功能?此外,我怎样才能使图像的纵横比适合全屏 View ?他们是否将 UIImage 发送到新的 View Controller ?

我当前的全屏图像方法只是将 UIImageView 的框架设置为与 super View 的框架相同,同时将 UINavigationBar 和 UITabBar 的 alpha 设置为 0。为了关闭,我添加了一个点击手势识别器来反转 alpha 并删除 UIImageView从 super View 。

这是我的全屏和关闭代码

func fullscreen(forImage image: UIImage) {
let imageView = UIImageView(image: image)
imageView.frame = self.view.frame
imageView.backgroundColor = .black
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.isUserInteractionEnabled = true

self.navigationController?.navigationBar.alpha = 0
self.tabBarController?.tabBar.alpha = 0

let dismissTap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
imageView.addGestureRecognizer(dismissTap)

self.view.addSubview(imageView)
}

@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
sender.view?.removeFromSuperview()
self.navigationController?.navigationBar.alpha = 1
self.tabBarController?.tabBar.alpha = 1
}

最佳答案

这可以使用 Apple 的 QuickLook 轻松实现框架,因为它适用于许多图像扩展和集合。

编辑:您想要的大部分功能都内置于 QLPreviewController

let previewController = QLPreviewController()
previewController.dataSource = self
self.present(previewController, animated: true, completion: nil)

数据源是任何符合 QLPreviewControllerDataSource 协议(protocol)的类

Here是来自 Apple 的视频指南,介绍如何轻松实现这一点

编辑:这部分在 previewItemAt 函数中进行

guard let url = Bundle.main.url(forResource: "imageName", withExtension: "jpg")
else {
fatalError("Could not load imageName.jpg")
}

return url as QLPreviewItem

关于ios - 如何全屏显示图像并通过类似于 Apple Photos 的滑动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54544467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com