Zoomy 4.0.0

Zoomy 4.0.0

Menno Lovink 维护。



Zoomy 4.0.0

  • 作者:
  • Menno Lovink

Version Platform License

Zoomy 允许您在任意视图层次结构中的 UIImageView 上添加无缝的 scrollView 和类似 Instagram 的缩放功能。

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

设置

只需将

import Zoomy

添加到需要放大行为的代码文件中。

使用方法

以下所有代码片段都应从您的 viewcontroller 内部调用。

viewDidLoad 之后某个地方运行应该没问题。

可滚动缩放

addZoombehavior(for: imageView)

Insta 缩放

addZoombehavior(for: imageView, settings: .instaZoomSettings)

在导航栏/标签栏上方缩放

guard let parentView = parent?.view else { return }
addZoombehavior(for: imageView, in:parentView)

在 UI 元素下方缩放

addZoombehavior(for: imageView, below: dismissButton)

使用某些自定义手势动作进行缩放

let settings = Settings.defaultSettings
    .with(actionOnTapOverlay: Action.dismissOverlay)
    .with(actionOnDoubleTapImageView: Action.zoomIn)
        
addZoombehavior(for: imageView, settings: settings)

还有很多其他 触发器操作 可以选择。

缩放 collectionviewcell

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
    //After your regular dequeue and configuration:
    addZoombehavior(for: cell.imageView)
        
    return cell
}

其他示例

pod try 'Zoomy' 加载示例项目。

或者直接查看一些示例代码

有关在 scrollview 内进行缩放图像的说明

使用 Zoomy 在任何视图层次结构中缩放都会工作得很好,但有时您想在缩放时禁用现有的行为。这的一个很好的例子是在缩放 scrollview 的子视图图像时。

为了最佳性能,只需实现这些 Zoomy.Delegate 方法

extension YourViewController: Zoomy.Delegate {
    
    func didBeginPresentingOverlay(for imageView: Zoomable) {
        scrollView.isScrollEnabled = false
    }
    
    func didEndPresentingOverlay(for imageView: Zoomable) {
        scrollView.isScrollEnabled = true
    }
}

无需将 viewController 设置为任何内容的代理。这通过条件遵从来推断。如果您对此感兴趣,请参阅

Texture

上述所有代码示例都适用于 texture 的 ImageNode。为此,您需要在目标源代码中添加 extension ASImageNode: Zoomable {}。有关 texture 基本及更高级使用方法的示例,请参阅示例项目。

精彩内容即将到来

请参阅 路线图 了解即将推出的功能。

缺少任何内容,或者某些内容没有按预期工作? 创建一个问题 ,很有可能会被处理。

支持

不一定总有时间为个人支持在不同场景中实现 Zoomy。希望代码足够清晰,可以完成所需的工作 💪。如果您在 readme 或示例中没有描述的任何场景实现了 Zoomy,请随时 创建一个 pull request ,实际上会很有趣。

安装

Zoomy 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'Zoomy'

致谢与鸣谢

封面照片由 Yip Leonardo 拍摄,所有其他使用的图片可在 Unsplash 上找到。

许可证

Zoomy 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。