DynamicBlurView is a dynamic and high performance UIView subclass for Blur.

Overview

DynamicBlurView

Carthage compatible Version License Platform

DynamicBlurView is a dynamic and high performance UIView subclass for Blur.

Appetize's Demo

homehome

  • Since using the CADisplayLink, it is a high performance.
  • Can generate a plurality of BlurView.

Requirements

  • Swift 5
  • iOS 8.0 or later
  • tvOS 9.0 or later

How to Install DynamicBlurView

CocoaPods

Add the following to your Podfile:

pod "DynamicBlurView"

Carthage

Add the following to your Cartfile:

github "KyoheiG3/DynamicBlurView"

Usage

Example

Blur the whole

let blurView = DynamicBlurView(frame: view.bounds)
blurView.blurRadius = 10
view.addSubview(blurView)

Animation

UIView.animateWithDuration(0.5) {
    blurView.blurRadius = 30
}

Ratio

blurView.blurRatio = 0.5

Variable

var blurRadius: CGFloat
  • Strength of the blur.
var trackingMode: TrackingMode
  • Mode for update frequency.
  • Common is constantly updated.
  • Tracking is only during scrolling update.
  • None is not update.
var blendColor: UIColor?
  • Blend in the blurred image.
var iterations: Int
  • Number of times for blur.
  • Default is 3.
var isDeepRendering: Bool
  • If the view want to render beyond the layer, should be true.
  • Default is false.
var blurRatio: CGFloat
  • When none of tracking mode, it can change the radius of blur with the ratio. Should set from 0 to 1.
  • Default is 1.
var quality: CaptureQuality
  • Quality of captured image.
  • Default is medium.

Function

func refresh()
  • Remove cache of blur image then get it again.
func remove()
  • Remove cache of blur image.
func animate()
  • Should use when needs to change layout with animation when is set none of tracking mode.

Acknowledgements

Author

Kyohei Ito

Follow me 🎉

LICENSE

Under the MIT license. See LICENSE file for details.

Comments
  • Black view

    Black view

    Just followed the iOS 8+ example and applied it to an image view and it shows a completely black view. Any ideas?

        if let imageView = self.bannerImage {
            let blurView = DynamicBlurView(frame: imageView.bounds)
            blurView.blurRadius = 10
            imageView.addSubview(blurView)
        }
    

    EDIT: This is called from awakeFromNib()

    opened by DiogoNeves 14
  • Black boxes when scrolling collection view.

    Black boxes when scrolling collection view.

    Hello! I'm trying to add this lib to an app where we have an UICollectionView and when I scroll through the cells, some of them turn into a black box for a fraction of the second. And also some of the blurred images go to the wrong cell.

    The problem happens when I scroll and change the blurView alpha to 0. (that change is done automatically on scrolling outside a certain offset)

    config:

            blurView.frame = textLabel.bounds
            blurView.drawsAsynchronously = true
            blurView.trackingMode = .tracking
            blurView.quality = .low
            blurView.isDeepRendering = true
            blurView.backgroundColor = .white
            blurView.iterations = 2
    
    opened by francocorreasosa 8
  • DynamicBlurView as subview of modal presented View Controller appear like view with black background

    DynamicBlurView as subview of modal presented View Controller appear like view with black background

    At UIViewController i add DynamicBlurView as subview. After that i present that View Controller modaly and DynamicBlurView looks like just black view.

    ` class BlurViewController: UIViewController {

    override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .clear

    let blur = DynamicBlurView(frame: CGRect(x: 20, y: 20, width: 300, height: 300))
    view.addSubview(blur)
    blur.blurRadius = 10
    blur.dynamicMode = .common
    

    } ` screen shot 2016-11-28 at 18 23 31

    opened by grishamsc 8
  • DynamicBlurView 5.0: crash on convertToARGB8888()

    DynamicBlurView 5.0: crash on convertToARGB8888()

    Hi ! First of all I would like to thank you for this library. After upgrading from 4.1 to 5.0 I get a crash from time to time. I'm using it along with PopupDialog. This is the stack trace. Thank you !

    Screenshot 2020-04-27 at 08 50 37
    opened by LaurentiuUngur 7
  • Swift 4.2 compatibility

    Swift 4.2 compatibility

    As of the upcoming official Swift 4.2 release, this PR incorporates the changes needed to support 4.2. Before the official release, I would recommend to merge this PR to a dedicated Swift 4.2 branch, which I am not able to do :)

    I did not bump version, though, as I think you have a better understanding on how you want to version DynamicBlurView.

    Hope that makes sense :)

    opened by mwfire 6
  • Swift 4.1 . Support

    Swift 4.1 . Support

    Doesn't build under latest Xcode 9.3 with Swift 4.1 compiler. Issue related to using private variables from DynamicBlurView extensions - so you just have to make them fileprivate

    opened by kuchmiyalex 4
  • Compilation issue: var current: `Self`

    Compilation issue: var current: `Self`

    Hello @KyoheiG3,

    'Self' is only available in a protocol or as the result of a method in a class; did you mean 'BlurLayer'?

    var current: Self {
            presentation() ?? self
    }
    

    Hope for your soonest solutions.

    • DynamicBlurView pod version: [5.0.2]
    • Xcode version: [11.3]
    • Your application language: [Swift-4.2]
    opened by akshardarji 3
  • is inaccessible due to 'private' protection level error

    is inaccessible due to 'private' protection level error

    I'm running an IOS 9.2 application which includes DynamicBlurView. It had been running without error and I just incurred 18 DynamicBlurView errors which states, "is inaccessible due to 'private' protection level error". How should I correct this issue.

    opened by pepper28 2
  • CGContextSetInterpolationQuality error

    CGContextSetInterpolationQuality error

    Here's that's spat out in the debugger:

    <Error>: CGContextSetInterpolationQuality: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
    
    opened by ky1ejs 2
  • Rarely does a black shadow occur

    Rarely does a black shadow occur

    Rarely does a black shadow occur

    • 1 , Once in a while appear shadow It's a tricky question, The iPhone 8 Plus and the iPhone 12 Mini have appeared sporadily so far.

    tapd_36120278_base64_1609828842_41

    opened by hwenxzhangling 1
  • Set CURRENT_PROJECT_VERSION to avoid validation error on submitting to the app store

    Set CURRENT_PROJECT_VERSION to avoid validation error on submitting to the app store

    When you install this library via carthage, CFBundleVersion is missing because CURRENT_PROJECT_VERSION is not set. This results in "Info.plist file is missing the required key: CFBundleVersion" error when you try to submit your app to the app store.

    It looks like there are other libraries having this issue. https://github.com/Flight-School/AnyCodable/issues/20#issuecomment-493263003

    opened by kiyot 1
  • This function contains crash info

    This function contains crash info

    func renderBelowLayer(_ layer: CALayer, in context: CGContext) { let layers = hideOverlappedLayers(layer.sublayers) layer.render(in: context) "context” may be nil layers.forEach { $0.isHidden = false } }

    opened by hwenxzhangling 1
  • Crash within the Blur Layer

    Crash within the Blur Layer

    Exception Type: SIGSEGV Exception Codes: SEGV_ACCERR at 0x16904ee488 Crashed Thread: 0

    Thread 0 Crashed: 0 CoreGraphics 0x00000001ed830ddc CGColorGetAlpha + 12 1 QuartzCore 0x00000001f0086bf4 -[CALayer _renderBorderInContext:] + 144 2 QuartzCore 0x00000001f0088b5c -[CALayer renderInContext:] + 1396 3 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 4 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 5 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 6 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 7 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 8 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 9 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 10 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 11 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 12 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 13 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 14 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 15 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 16 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 17 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 18 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 19 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 20 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 21 QuartzCore 0x00000001f0086ea4 -[CALayer _renderSublayersInContext:] + 368 22 QuartzCore 0x00000001f0088b48 -[CALayer renderInContext:] + 1376 23 DynamicBlurView 0x00000001060da560 DynamicBlurView.BlurLayer.render(in: __C.CGContextRef, for: __C.CALayer) -> () (BlurLayer.swift:94) 24 DynamicBlurView 0x00000001060df684 DynamicBlurView.DynamicBlurView.(snapshotImage in _2044C6510BFEB36C5566C936E3D26E26)(for: __C.CALayer, conversion: Swift.Bool) -> __C.UIImage? (DynamicBlurView.swift:142) 25 DynamicBlurView 0x00000001060dffd8 function signature specialization <Arg[0] = Dead> of DynamicBlurView.DynamicBlurView.display(__C.CALayer) -> () (DynamicBlurView.swift:156) 26 DynamicBlurView 0x00000001060df7b4 @objc DynamicBlurView.DynamicBlurView.display(__C.CALayer) -> () (:0) 27 DynamicBlurView 0x00000001060df934 DynamicBlurView.DynamicBlurView.refresh() -> () (DynamicBlurView.swift:180) 28 PopupDialog 0x000000010ae77240 PopupDialog.PresentationController.containerViewWillLayoutSubviews() -> () (PresentationController.swift:58) 29 PopupDialog 0x000000010ae77288 merged @objc PopupDialog.PresentationController.presentationTransitionWillBegin() -> () + 24 30 UIKitCore 0x0000000219386fe4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1116 31 libobjc.A.dylib 0x00000001eacab454 -[NSObject performSelector:withObject:] + 64 32 QuartzCore 0x00000001f0083db4 -[CALayer layoutSublayers] + 184 33 QuartzCore 0x00000001f00840a0 CA::Layer::layout_if_needed(CA::Transaction*) + 332 34 QuartzCore 0x00000001f0083f1c -[CALayer layoutIfNeeded] + 228 35 QuartzCore 0x00000001f0088690 -[CALayer renderInContext:] + 168 36 DynamicBlurView 0x00000001060da560 DynamicBlurView.BlurLayer.render(in: __C.CGContextRef, for: __C.CALayer) -> () (BlurLayer.swift:94) 37 DynamicBlurView 0x00000001060df684 DynamicBlurView.DynamicBlurView.(snapshotImage in _2044C6510BFEB36C5566C936E3D26E26)(for: __C.CALayer, conversion: Swift.Bool) -> __C.UIImage? (DynamicBlurView.swift:142) 38 DynamicBlurView 0x00000001060de828 DynamicBlurView.DynamicBlurView.didMoveToWindow() -> () (DynamicBlurView.swift:86) 39 DynamicBlurView 0x00000001060de944 merged @objc DynamicBlurView.DynamicBlurView.didMoveToWindow() -> () + 24 40 UIKitCore 0x000000021937e288 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1604 41 UIKitCore 0x000000021937dedc -[UIView(Internal) _didMoveFromWindow:toWindow:] + 664 42 UIKitCore 0x00000002193712ac __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 156 43 Foundation 0x00000001ec437634 -[NSISEngine withBehaviors:performModifications:] + 112 44 UIKitCore 0x000000021937118c -[UIView(Hierarchy) _postMovedFromSuperview:] + 816 45 UIKitCore 0x0000000219380d20 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1740 46 PopupDialog 0x000000010ae76d74 PopupDialog.PresentationController.presentationTransitionWillBegin() -> () (PresentationController.swift:40) 47 PopupDialog 0x000000010ae77288 merged @objc PopupDialog.PresentationController.presentationTransitionWillBegin() -> () + 24 48 UIKitCore 0x000000021882dc8c __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 2224 49 UIKitCore 0x000000021882b6e0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 468 50 UIKitCore 0x000000021890fa64 __40+[UIViewController _scheduleTransition:]_block_invoke + 24 51 UIKitCore 0x0000000218edd1fc _runAfterCACommitDeferredBlocks + 300 52 UIKitCore 0x0000000218ecb3bc _cleanUpAfterCAFlushAndRunDeferredBlocks + 352 53 UIKitCore 0x0000000218ef9a3c _afterCACommitHandler + 116 54 CoreFoundation 0x00000001eba3a0e8 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 32 55 CoreFoundation 0x00000001eba34be0 __CFRunLoopDoObservers + 412 56 CoreFoundation 0x00000001eba35140 __CFRunLoopRun + 1208 57 CoreFoundation 0x00000001eba34964 CFRunLoopRunSpecific + 448 58 GraphicsServices 0x00000001edc75d8c GSEventRunModal + 104 59 UIKitCore 0x0000000218ed1758 UIApplicationMain + 212 60 VW-R-CLUB Member APP 0x000000010292ffdc main (AppDelegate.swift:20) 61 libdyld.dylib 0x00000001eb4f0fd8 start + 0

    crash report:

    func render(in context: CGContext, for layer: CALayer) {
        let layers = hideOverlappingLayers(layer.sublayers)
        layer.render(in: context)    <------------------------------ here
        layers.forEach {
            $0.isHidden = false
        }
    }
    
    
    private func snapshotImage(for layer: CALayer, conversion: Bool) -> UIImage? {
        let rect = blurLayerRect(to: layer, conversion: conversion)
        guard let context = CGContext.imageContext(with: quality, rect: rect, opaque: isOpaque) else {
            return nil
        }
    
        blurLayer.render(in: context, for: layer)  <------------------------------ here
    
        defer {
            UIGraphicsEndImageContext()
        }
    
        return UIGraphicsGetImageFromCurrentImageContext()
    }
    
    
    extension DynamicBlurView {
    open override func display(_ layer: CALayer) {
        let blurRadius = blurLayer.presentationRadius
        let isFixes = isDeepRendering && staticImage != nil
        if let view = renderingTarget, let image = staticImage ?? snapshotImage(for: view.layer, conversion: !isFixes) {   <------------------------------ here <Arg[0] = Dead> of DynamicBlurView.DynamicBlurView.display(__C.CALayer) -> () (DynamicBlurView.swift:156)
            draw(image, blurRadius: blurRadius, fixes: isFixes, baseLayer: view.layer)
        }
    }
    

    }

    extension DynamicBlurView {
    /// Remove cache of blur image then get it again.
    open func refresh() {
        blurLayer.refresh()
        staticImage = nil
        blurRatio = 1
        display(layer) <------------------------------ here
    }
    

    Hope you can help me to fix it.

    The crash only happens sometimes.

    opened by Skyb0rg 18
  • [Unknown process name] CGImageCreate: invalid image alphaInfo: kCGImageAlphaNone. It should be kCGImageAlphaNoneSkipLast

    [Unknown process name] CGImageCreate: invalid image alphaInfo: kCGImageAlphaNone. It should be kCGImageAlphaNoneSkipLast

    When using this component i keep getting the following log out 20 times a second

    [Unknown process name] CGImageCreate: invalid image alphaInfo: kCGImageAlphaNone. It should be kCGImageAlphaNoneSkipLast

    opened by sadiq81 0
Releases(5.0.0)
Owner
Kyohei Ito
Kyohei Ito
Colorful - A SwiftUI implementation of AppleCard's animated colorful blur background.

Colorful - A SwiftUI implementation of AppleCard's animated colorful blur background.

Lakr Aream 200 Jan 3, 2023
MotionBlur allows you to add motion blur effect to iOS animations.

MotionBlur MotionBlur allows you to add motion blur effect to your animations (currently only position's change). See the accompanying blog post to le

Arek Holko 1.5k Nov 3, 2022
Widgets iOS 14 animation with 3D and dynamic shadow. Customisable transform and duration.

SPPerspective About Animatable widgets from iOS 14. Same animation for transform and shadow. Customisable duration, perspective and shadow also. For v

Ivan Vorobei 290 Dec 29, 2022
Fortune spinning wheel library built using SwiftUI, supports dynamic content.

Fortune Wheel Fortune spinning wheel ?? library built using SwiftUI, supports dynamic content. Preview - Spin Wheel ⚙️ CocoaPods Installation FortuneW

Sameer Nawaz 51 Dec 23, 2022
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
UIImageView subclass that allows you to display a looped video and dynamically switch it.

AKVideoImageView Motivation AKVideoImageView was created because I wasn't satisfied with the standard AVPlayer when I was implementing a video backgro

Oleksandr Kirichenko 125 Apr 5, 2022
Simple UIButton subclass with additional state change animations (e.g. backgroundColor) and missing features

SimpleButton UIButton subclass with animated, state-aware attributes. Easy to subclass and configure! Full API docs Usage Just create your own SimpleB

Andreas Tinoco Lobo 169 Sep 14, 2022
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
Run animations at high frame rates on iPhone 13 Pro

Run animations at high frame rates on iPhone 13 Pro Background When using a UIViewPropertyAnimator to animate objects on iPhone 13 Pro, CoreAnimation

Duraid Abdul 5 Aug 8, 2022
BWMCoverView is a very easy to use advertising the carousel view, supports circular scrolling functions such as switching, asynchronous loading of images, animation, custom is very high.

BWMCoverView BWMCoverView is a very easy to use advertising the carousel view, supports circular scrolling functions such as switching, asynchronous l

Bi Weiming 31 Mar 10, 2021
A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.

AnimatedCollectionViewLayout Normally a UICollectionView has no transition effects when you scroll from one item to another. There are lots of ways to

Jin Wang 4.5k Jan 1, 2023
DaisyChain is a micro framework which makes UIView animations chaining dead simple.

DaisyChain DaisyChain is a micro framework which makes UIView animations chaining dead simple. It uses the exact same interface you are familiars with

Ali Karagoz 31 Nov 3, 2022
UIView category that adds shake animation

UIView category that adds a shake animation like the password field of the OSX login screen. Screenshot Setup with CocoaPods Add pod 'UIView+Shake' to

Andrea Mazzini 498 Nov 20, 2022
Chain multiple UIView animations without endlessly nesting in completion closures.

⛓ Chain multiple UIView animations without endlessly nesting in completion closures. Used in some of the more superfluous animations in the OK Video app.

Pim 78 Dec 26, 2022
Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

IBAnimatable 8.6k Jan 2, 2023
Letters animation allows you to click on different letters and accordingly it will animate letters in a cool way. It has a very attractive UI and is very easy to use.

Letters Animation Cool Letters Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 31 Oct 4, 2022
Numbers animation allows you to click on different numbers and accordingly it will animate numbers in a cool way. It has a very attractive UI and is very easy to use.

Numbers Animation Cool Numbers Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 31 Oct 4, 2022
Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.

Reading Animation Cool Reading Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 42 Oct 4, 2022