• Stars
    star
    302
  • Rank 138,030 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A pure Swift high-performance asynchronous image loading framework. SwiftUI supported.

Longinus



Longinus

Longinus is a pure-Swift high-performance asynchronous web image loading,caching,editing framework.

It was learned from Objective-C web image loading framework YYWebImage and BBWebImage, bring lots of high performace features to Swift. It may become a better choice for you.

Longinus's goal is to become the Highest-Performance web image loading framework on Swift.

Feature

  • Asynchronous image downloading and caching.
  • Preload images and cache them to disk for further showing.
  • Animated GIF support (dynamic buffer, lower memory usage).
  • Baseline/progressive/interlaced image decode support.
  • View extensions for UIImageView, UIButton, MKAnnotationView(not yet) and CALayer to directly set an image from a URL.
  • Built-in transition animation when setting images.(or you can set your custom image showing transion)
  • Image Transform after downloading supported: blur, round corner, resize, color tint, crop, rotate and more.
  • High performance memory and disk image cache. Use LRU algorithm to manage. For disk cache, it use file system and sqlite for better performance.
  • Use FIFO queue to handle image downloading operation.
  • Smooth sliding without UI lags. High performance image caching and decoding to avoid main thread blocked.
  • SwiftUI support.

Usage

The simplest use-case is setting an image to an image view with the UIImageView extension:

let url = URL(string: "http://github.com/logo.png")
imageView.lg.setImage(with: url)

Load animated gif image:

let url = URL(string: "https://ww4.sinaimg.cn/bmiddle/eaeb7349jw1ewbhiu69i2g20b4069e86.gif")
imageView.lg.setImage(with: url)

Load image progressively:

let url = URL(string: "http://github.com/logo.png")
imageView.lg.setImage(with: url, options: [.progressiveBlur, .imageWithFadeAnimation])

Load and transform image:

let url = URL(string: "https://ww4.sinaimg.cn/bmiddle/eaeb7349jw1ewbhiu69i2g20b4069e86.gif")
let transformer = ImageTransformer.imageTransformerCommon(with: imageView.frame.size, borderWidth: 2.0, borderColor: .white)
imageView.lg.setImage(with: url, options: [.progressiveBlur, .imageWithFadeAnimation], transformer: transformer)

Usage in SwiftUI:

import SwiftUI

// 1. If you are using SPM or Carthage, the SwiftUI support is defined in a new module.
import LonginusSwiftUI

// 2. If you are using CocoaPods, in which the SwiftUI support is defined in the Longinus module.
//    Here we choose to just import the `LGImage` type instead of the whole module, 
//    to prevent the conflicting between `Longinus.View` and `SwiftUI.View`
import struct LonginusSwiftUI.LGImage

var body: some View {
    LGImage(source: URL(string: "https://github.com/KittenYang/Template-Image-Set/blob/master/Landscape/landscape-\(index).jpg?raw=true"), placeholder: {
            Image(systemName: "arrow.2.circlepath")
                .font(.largeTitle) })
        .onProgress(progress: { (data, expectedSize, _) in
            print("Downloaded: \(data?.count ?? 0)/\(expectedSize)")
        })
        .onCompletion(completion: { (image, data, error, cacheType) in
            if let error = error {
                print(error)
            }
            if let _ = image {
                print("Success!")
            }
        })
        .resizable()
        .cancelOnDisappear(true)
        .aspectRatio(contentMode: .fill)
        .frame(width: 300, height: 300)
        .cornerRadius(20)
        .shadow(radius: 5)
}

Requirements

  • iOS 10.0+
  • Swift 5.0+
  • SwiftUI 13.0+

Installation

CocoaPods

Longinus is available through CocoaPods. To install it, simply add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target 'MyApp' do
  # your other pod
  # ...
  pod 'Longinus'
  # SwiftUI support is provided in a sub-spec. 
  # So instead of specifying pod 'Longinus', 
  # you need:
  # pod 'Longinus/SwiftUI'
end

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

For more information about how to use CocoaPods, I suggest this tutorial.

Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew.

To integrate Longinus into your Xcode project using Carthage, specify it in your Cartfile:

github "KittenYang/Longinus" ~> 1.0

Then, run the following command to build the Longinus framework:

$ carthage update

Swift Package Manager

From Xcode 11, you can use Swift Package Manager to add Longinus to your project.

Select File > Swift Packages > Add Package Dependency. Enter https://github.com/KittenYang/Longinus.git in the "Choose Package Repository" dialog.

Benchmark

I tested some popular web image loading frameworks on iOS platform from some aspects.

  • Image loading speed.
  • Memory&Disk read/write/delete speed.
  • Scrolling 4000 images UI fps.

Here is the tested results. (Lower is better)

Note: The test device is iPhone 11, running on iOS 13.3

You can git clone this repo and run the Benchmark.xcworkspace to test it by yourself.

License

Longinus is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

KYGooeyMenu

A not bad gooey effects menu.
Objective-C
1,921
star
2

A-GUIDE-TO-iOS-ANIMATION

The source code of my new eBook —— A GUIDE TO IOS ANIMATION. Just click the next link to buy it
Objective-C
1,453
star
3

KYAnimatedPageControl

A custom UIPageControl with multiple animations
Objective-C
1,317
star
4

KYCuteView

Drag like a gooey bubble.
Objective-C
979
star
5

GooeyTabbar

A gooey effect tabbar
Swift
937
star
6

Animations

some test animations, just for fun.
Objective-C
629
star
7

KYJellyPullToRefresh

A shape changing & physical ball pull-to-refresh.
Objective-C
559
star
8

KYWaterWaveView

实现波浪正弦动画并带有小鱼跳跃溅起水花。A view with water wave animation inside.
Objective-C
515
star
9

KYElegantPhotoGallery

An elegant photo gallery. It will zoom from a thumb image and you can pan to dismiss it with cool animation.
Objective-C
423
star
10

DynamicMaskSegmentSwitch

A segment switcher with dynamic text mask effect
Swift
309
star
11

KYTilePhotoLayout

A UICollectionViewLayout with a really interesting image layout algorithm.
Objective-C
228
star
12

KYPingTransition

实现圆圈放大放小的转场动画
Objective-C
205
star
13

KYMagicMove

在iOS中实现Keynote中神奇移动的过渡效果
Objective-C
194
star
14

KYBezierBounceView

实现手势控制贝塞尔曲线的左右菜单并带有重力反弹效果
Objective-C
136
star
15

KYAsyncLoadBubble

A bubble which can async-load web content without interrupt your current process.
Objective-C
113
star
16

KYPushTransition

一个3D翻转的转场动画
Objective-C
103
star
17

KYShareMenu

带弹性动画的分享菜单
Objective-C
86
star
18

KYFloatingBubble

类似iOS7中Game Center浮动气泡的效果。iOS7 Game Center Floating Bubble Effects.
Swift
82
star
19

KYParallaxView

一个使用简单同时又能高度自定义的视差滚动框架
Objective-C
73
star
20

ChatGPT-Mac-MenuBar

Chat with OpenAI's ChatGPT in mac menu bar like a pro.
Swift
72
star
21

KYJellyAnimation

实现类似Skype iOS App中果冻弹簧效果
Objective-C
58
star
22

KYVoiceCurve

类似Apple Watch中语音的声音曲线动画。The animating voice curve like Apple Watch
Objective-C
57
star
23

KYWeibo

调用新浪API自己写的第三方微博客户端
Objective-C
45
star
24

KYSelfSizingPushFixCategory

A UITableView Category for fixing the bug of 'Self-Sizing-Cell' when push to next ViewController the tableView position will change.
Ruby
30
star
25

KYCellAnimation

给UITableViewCell增加进入的动画
Objective-C
24
star
26

KYNewtonCradleAnimiation

牛顿摆动画
Objective-C
23
star
27

zigzag_wechat_bot

ZigZag 做市商微信机器人
TypeScript
19
star
28

KYPageControlTry

类似Smartisan OS首页的小圆点滚动效果
Objective-C
19
star
29

SpringPageView

使用POP
Objective-C
18
star
30

SafeSnap

An open-sourced Web3 iOS Application which combines Gnosis Safe and Snapshot together makes you easily manage your DAOs on your pocket.
Swift
17
star
31

PassbookCard

A card animation like Passbook.
Objective-C
15
star
32

SoundCloudWaveView

A controllable sound wave view like Sound Cloud.
Objective-C
15
star
33

KYTransition

A custom transition using UIViewControllerTransitioning
Objective-C
13
star
34

GooeyLoader

The implement of Scanner Gooey Effect: https://dribbble.com/shots/2156764-Scanner-Gooey-Effect-Firefly-Loader
Swift
12
star
35

DynamicBlurView

A high performance UIView-Class dynamic blur view like UITabbar or UINavagationBar, it can blur the view behind it.
Objective-C
12
star
36

WeiboEmotionView

The Weibo Emotion View you can use in replace of your keyboard.
Objective-C
11
star
37

FaceTrigger

An easy-to-use wrapper of ARKit Face Tracking API
Swift
9
star
38

RecordAppScreen

Record screen inside app.
Swift
9
star
39

SwiftQ-A

学习Swift过程中自己出的一些Q&A,方便巩固知识点。Swift learning Q&A.
Swift
8
star
40

KYDoubanFM

纯Swift第三方豆瓣FM客户端
Swift
7
star
41

FloatingVideoView

A floating video view test, seems like VVebo.
Objective-C
7
star
42

Performance-Optimization-PDF

The slices of Performance-Optimization presentation
6
star
43

CustomActivities

UIActivity extention for weibo/wechat/tencent
Objective-C
4
star
44

ElegantPhotoGallery

The swift version of KYElegantPhotoGallery.
4
star
45

charming-chatgpt

A raycast extension for charming-chatgpt
TypeScript
4
star
46

AnimatedPageControl

The swift version of KYAnimatedPageControl.
4
star
47

TapticEngineSample

A sample of how to use Taptic Engine API(UINotificationFeedbackGenerator/UIImpactFeedbackStyle/UIImpactFeedbackGenerator)
Swift
4
star
48

NewNextApp

My personal app.Still moving.
Makefile
3
star
49

KYDopePopup

A drop-in AlertViewController with dope animation.
Objective-C
3
star
50

AutoGPT.swift

AutoGPT with Swift
Swift
3
star
51

TenderCrashHandlerDemo

Tender crash solution.
Objective-C
3
star
52

KYVoiceCurve-Swift

KYVoiceCurve for Swift
Swift
2
star
53

KYMotionBlur

在iOS上实现一种特殊的视觉效果——运动模糊
2
star
54

KYNavigationTranstion

An easiest way of NavigationTransition.
1
star
55

SDThumbnailDecodingPeakMemoryTest

A demo to compare SD 5.x Thumbnail Decoding and SD 4.x Downsizing peak memory
Objective-C
1
star
56

kittenyang

1
star
57

QuickOpenCellular

Swift
1
star
58

NextApp

focus开发的一个完整的项目,不再继续,接力给NewNextApp继续开发。
Makefile
1
star
59

HowRegexWorks-Swift

用Swift学习正则表达式是如何工作的(笔记+源码)
Swift
1
star