FocusableImageView 0.1.0

FocusableImageView 0.1.0

Koji Murata 维护。



  • 作者
  • Koji Murata

可聚焦的ImageView SwiftPM兼容 Carthage兼容 CocoaPods 许可

Screenshot

最小示例

import UIKit
import FocusableImageView

class ViewController: UIViewController {
    @IBOutlet private weak var stackView: UIStackView!
    private let manager = FocusableImageViewManager()
    private var imageViews: [FocusableImageView] { stackView.arrangedSubviews as! [FocusableImageView] }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        manager.register(parentViewController: self, imageViews: imageViews)
    }
}

安装

SwiftPM (推荐)

  • 在 Xcode 中,点击 文件 > Swift 包 > 添加依赖...
  • 输入 https://github.com/malt03/FocusableImageView.git

Carthage

  • 在您的 Cartfile 中插入 github "malt03/FocusableImageView"
  • 运行 carthage update
  • 将您的应用与 Carthage/Build 中的 FocusableImageView.framework 链接。

CocoaPods

  • 在您的Podfile中添加pod 'FocusableImageView'
  • 运行pod install

高级示例

访问内部UIImageView

imageView.inner.kf.setImage(url) // Set Image URL with Kingfisher

ImageView 的附加动画

manager.delegate = self

extension ViewController: FocusableImageViewDelegate {
    func selectableImageViewPresentAnimation(views: [FocusableImageView]) {
        views.forEach { $0.inner.layer.cornerRadius = 0 }
    }
    
    func selectableImageViewDismissAnimation(views: [FocusableImageView]) {
        views.forEach { $0.inner.layer.cornerRadius = 8 }
    }
}

设置配置

manager.configuration = .init(
    backgroundColor: .init(white: 0, alpha: 0.5),
    animationDuration: 0.5,
    pageControlConfiguration: .init(hidesForSinglePage: false, pageIndicatorTintColor: nil, currentPageIndicatorTintColor: nil),
    maximumZoomScale: 2,
    createDismissButton: { (parentView) -> UIButton in
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle("Close", for: .normal)
        button.setTitleColor(.white, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        parentView.addSubview(button)
        NSLayoutConstraint.activate([
            button.leadingAnchor.constraint(equalTo: parentView.leadingAnchor, constant: 16),
            button.topAnchor.constraint(equalTo: parentView.safeAreaLayoutGuide.topAnchor, constant: 16),
        ])
        return button
    }
)

默认配置

FocusableImageViewConfiguration.default = configuration