登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

轻量级 全屏图片/视频浏览器 Swift 4 MVVM

[复制链接]
来自: SchweinFliege 分类: iOS精品源码 上传时间: 2018-3-2 11:28:44
Tag:

项目介绍:

Github: https://github.com/pigfly/A_J_Full_Screen_Image_Browser

A-J-Full-Screen-Image-Browser

Travis
Code
Swift
npm

A-J-Full-Screen-Image-Browser is an drop-in solution for full screen image and video browser

Features

  • [x] No Dependency, 100% iOS Native

  • [x] Support both iPad and iPhone family

  • [x] Support image resizing on different screen orientation

  • [x] Image can be panned, zoomed and rotated

  • [x] Double tap to zoom all the way in and again to zoom all the way out

  • [x] Swipe to dismiss

  • [x] High level diagram

  • [x] MVVM architecture

  • [x] Full documentation

  • [x] Easy to customise

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+

  • Xcode 8.3+

  • Swift 3.1+

Installation

  • drag and drop the entire A_J_Full_Screen_Image_Browser into your project

Full Usage Example

import UIKit

final class ViewController: UIViewController {

    lazy var images: [ImageAsyncDownloadable] = {
        return [SingleImage(imageURL: URL(string: "https://images.unsplash.com/photo-1445264918150-66a2371142a2?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=79730c9ec106e3ccee026c648c624e5f&auto=format&fit=crop&w=3800&q=80")!),
                SingleImage(imageURL: URL(string: "https://images.unsplash.com/photo-1483086431886-3590a88317fe?ixlib=rb-0.3.5&s=96129ab02a4a277f5c27273d14323a9a&auto=format&fit=crop&w=3668&q=80")!)]
    }()

    lazy var urls = [URL(string: "https://images.unsplash.com/photo-1502899576159-f224dc2349fa?ixlib=rb-0.3.5&s=4f3943a5d663f9bb062d7d380c8d6fdf&auto=format&fit=crop&w=3700&q=80")!,
                     URL(string: "https://images.unsplash.com/photo-1445264918150-66a2371142a2?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=79730c9ec106e3ccee026c648c624e5f&auto=format&fit=crop&w=3800&q=80")!]

    lazy var videoUrl = URL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!

    @IBAction func onButtonTapped(_ sender: UIButton) {
        let vm = FullScreenImageBrowserViewModel(urls: urls, videoUrl: videoUrl)
        let x = FullScreenImageBrowser(viewModel: vm)
        present(x, animated: true, completion: nil)
    }

AlamofireImage Support

By default, FullScreenImageBrowser doesn't use any 3rd library, the SingleImage uses URLSession to fetch image. However it's designed to be compatible with any networking library, one good example is AlamofireImage

The following code snippet shows an example how to use AlamofireImage to seamlessly integrated with FullScreenImageBrowser.

import Foundation
import AlamofireImage

public class FullScreenImage: ImageAsyncDownloadable {
    public var image: UIImage?
    public var imageURL: URL?

    private let downloader = ImageDownloader()

    public init(imageURL: URL?) {
        self.imageURL = imageURL
    }

    public func loadImageWithCompletionHandler(_ completion: @escaping (UIImage?, NSError?) -> Void) {
        if let image = image {
            completion(image, nil)
            return
        }
        loadImageWithURL(imageURL, completion: completion)
    }

    // use any network calls you like
    public func loadImageWithURL(_ url: URL?, completion: @escaping (_ image: UIImage?, _ error: NSError?) -> Void) {
        guard let _url = url else {
            completion(nil, NSError(domain: "FullScreenImageBrowserDomain",
                                    code: -2,
                                    userInfo: [ NSLocalizedDescriptionKey: "Image URL not found."]))
            return
        }
        let urlRequest = URLRequest(url: _url)

        downloader.download(urlRequest) { [weak self] response in
            debugPrint(response.result)

            if let remoteImage = response.result.value {
                self?.image = remoteImage
                completion(remoteImage, nil)
            } else {
                completion(nil, NSError(domain: "FullScreenImageBrowserDomain",
                                        code: -1,
                                        userInfo: [ NSLocalizedDescriptionKey: "Couldn't load image from remote"]))
            }
        }
    }
}

Folder Structure

├── animator
│   └── FullScreenImageTransitionAnimator.swift
├── asset
│   └── FullScreenImageBrowser.bundle
│       ├── close.png
│       ├── close@2x.png
│       └── close@3x.png
├── core
│   ├── FullScreenImageBrowser.swift
│   ├── FullScreenImageBrowserViewModel.swift
│   ├── Image+AsyncDownload.swift
│   ├── MaskImageViewer.swift
│   ├── SingleImageViewer.swift
│   └── ZoomableImageView.swift
└── helper
    ├── SingleImage.swift
    └── UIView+SnapShot.swift
FileResponsiblity
animatorcustomised fade in/fade out animations with damping factors
assetcustomised static image asset for the full screen image/video browser navigation bar
core/FullScreenImageBrowsermanager class to be responsible for full screen image/video browser
core/FullScreenImageBrowserViewModeldatasource and business logic for full screen image/video browser
core/Image+AsyncDownloadprotocol to define images to be able to asynchronously download
core/MaskImageViewercustomised overlay view for full screen image/video browser
core/SingleImageViewerview controller to be responsible for single image rendering on the full screen
core/ZoomableImageViewview to add support for image to zoom, pin, rotate, and animation

Demo

HLD

Credits

A-J-Full-Screen-Image-Browser is owned and maintained by the Alex Jiang. Thanks iTMan.design for providing computational resources.

License

A-J-Full-Screen-Image-Browser is released under the MIT license.

相关源码推荐:

我来说两句
*滑动验证:
所有评论(13)
逆鳞九霄 2018-3-5 10:27:02
淡定,淡定,淡定……
回复
码农创新者 2018-3-5 10:27:32
学习...学习...
回复
t8569 2018-3-5 10:27:48
虽不明,但觉厉...
回复
莫应有道 2018-3-5 10:28:02
相当不错,感谢无私分享精神!
回复
bug是啥 2018-3-5 10:28:11
内容很好,棒棒哒
回复
littleRed 2018-3-5 10:28:13
我是来学习的
回复
A7472 2018-3-5 10:28:14
我是来学习的
回复
code4app热心网友 2018-3-5 17:23:13
很给力,Code4App有你更精彩!
回复
code4app热心网友 2018-3-6 16:34:05
楼主威武啊,Code4App有你更给力!
回复
12下一页
提取码:  下载次数:19 状态:已购或VIP 售价:0(原价:15)金钱 下载权限:初级码农 
1156 0 19
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 广东互联网违法和不良信息举报中心|中国互联网举报中心|Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表