Giter VIP home page Giter VIP logo

visualeffectview's Introduction

VisualEffectView

Swift Build Status Carthage compatible Language Version License

VisualEffectView is a blur effect library with tint color support. This library uses the UIVisualEffectView to generate the blur.

$ pod try VisualEffectView

Requirements

  • iOS 9.0+
  • iOS 14.0 + (SwiftUI support)
  • Xcode 9.0+
  • Swift 5 (VisualEffectView 4.x), Swift 4 (VisualEffectView 3.x), Swift 3 (VisualEffectView 2.x), Swift 2 (VisualEffectView 1.x)

Usage

Add an instance of VisualEffectView to your view.

import VisualEffectView

let visualEffectView = VisualEffectView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))

// Configure the view with tint color, blur radius, etc
visualEffectView.colorTint = .redColor()
visualEffectView.colorTintAlpha = 0.2
visualEffectView.blurRadius = 10
visualEffectView.scale = 1

addSubview(visualEffectView)

Depending on the desired effect, the effect may affect content layered behind the view or content added to the visual effect view’s contentView. After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself. Refer to the UIVisualEffectView for more info.

For more examples, take a look at the example project.

Customization

var colorTint: UIColor // tint color. default is nil
var colorTintAlpha: CGFloat // tint color alpha. default is 0
var blurRadius: CGFloat // blur radius. default is 0
var scale: CGFloat // scale factor. default is 1

If you want colorTintAlpha to be different from 0, make sure you always set it right after setting the colorTint or it may not be applied as expected. You also have to make sure you don't set colorTintAlpha if colorTint is nil.

Storyboard Support

Works great with storyboards and xibs.

SwiftUI Support

VisualEffectView supports SwiftUI.

import VisualEffectView

struct ContentView: View {
    var body: some View {
        VisualEffect(colorTint: .white, colorTintAlpha: 0.5, blurRadius: 18, scale: 1)
    }
}

Make sure that colorTintAlpha is not set when colorTint is nil.

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "VisualEffectView"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/VisualEffectView"

Manually

  1. Download and drop VisualEffectView.swift in your project.
  2. Congratulations!

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Disclaimer

VisualEffectView utilizes a private UIKit API to do its magic. Use caution, submitting this code to the App Store adds the risk of being rejected!

Credits

https://github.com/collinhundley/APCustomBlurView

License

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

visualeffectview's People

Contributors

amaurydavid avatar efremidze avatar kirillmagerya avatar lfarah avatar mlch911 avatar mxcl avatar rishabhtayal avatar underthestars-zhy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

visualeffectview's Issues

is not working in iOS 14

it is working if you add this

func setValue( value: T, forKey key: Key) {
blurEffect.setValue(value, forKeyPath: key.rawValue)
if #available(iOS 14, *) { } else {
self.effect = blurEffect
}
}

Not working on iOS 14

Unfortunately this library stopped working correctly on iOS 14. No blur is being displayed at all

Video not work

Hi,

The video on readme not work, link is broken.

Thanks.

Crashes on iOS 13 when tintColor is nil

Hello,
I wanted to try out the latest version (4.1.1) with the iOS 14 fix but now I've got some crashes on iOS 13.5.

func newVisualEffectView(tint: UIColor? = nil) -> VisualEffectView {
        let view = VisualEffectView(frame: self.view.frame)
        view.colorTint = tint
        view.colorTintAlpha = 0.92
        view.blurRadius = 7
        view.scale = 1
        return view
}

This raises a runtime error when tint is nil:

func _setValue<T>(_ value: T, forKey key: Key) {
        blurEffect.setValue(value, forKeyPath: key.rawValue)
        if #available(iOS 14, *) {} else {
            self.effect = blurEffect // <- -[NSNull _backgroundColorIgnoringHighContrast]: unrecognized selector sent to instance 0x7fff8062d9d0
        }
}

So I've added a check to not set the colorTintAlpha if there was no tintColor:

func newVisualEffectView(tint: UIColor? = nil) -> VisualEffectView {
        let view = VisualEffectView(frame: self.view.frame)
        view.colorTint = tint
        if view.colorTint != nil {
            view.colorTintAlpha = 0.92
        }
        view.blurRadius = 7
        view.scale = 1
        return view
}

This raises another runtime error when trying to access the tintColor from the new condition:

func _value<T>(forKey key: Key) -> T {
        return blurEffect.value(forKeyPath: key.rawValue) as! T // <- Could not cast value of type 'NSNull' (0x7fff87a92380) to 'UIColor' (0x7fff897eb788).
}

height and width Constraints not working

`let effect = VisualEffectView()//VisualEffectView(frame: CGRect(x: 0, y: 0, width: 600, height: 600))
effect.translatesAutoresizingMaskIntoConstraints = false
effect.colorTint = .red
effect.colorTintAlpha = 0.2
effect.blurRadius = 10
effect.scale = 1

    view.addSubview(effect)
    effect.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0).isActive = true
    effect.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0).isActive = true

`

Blur effect apply on Status Bar

Is there any way to apply Blur effect on Status Bar view.

Please note that This is not the Bug BUT in iPhone blue effect apply on whole screen area include status bar Real time and battery icon too.

Thanks in Advance.

Manual Installation

CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

iOS 8.x crash

Hello,

I'm using VisualEffectView to find a custom UIVisualEffectView.
When I read ReadMe, iOS 8.0 + is actually crashing when iOS 8.x is run.

private let blurEffect = (NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type).init()

fatal error: unexpectedly found nil while unwrapping an Optional value

it's probably an iOS9+ API

Tint color or blurRadius issues with iOS 16

IOS 16 was recently updated, The same code shows the result, which is very different from what it was before iOS 16, Below is the 16 and 16 before the rendering
please help me to solve the problem

Swift 3.0 syntax

Please update your project to Swift 3 syntax. When I reinstall pods each time I have to convert syntax of your library.

Redundant blue half-transparent overlay on iOS 14

Changing colorTint = .clear not solves the problem.
It seems like colorTint had effect on _UIVisualEffectSubview, but blue overlay is in _UIVisualEffectBackdropView.

I was expecting that will find a solution here, but now think that only I have this problem.

iPhone 11 – 14 0 2020-09-24 09-27-03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.