How can I make the UIView transparent with wallpaper - ios

Apple's iPod app and Remote app can see the a blurred version of the wallpaper image, as you can see the image below:
I really like this effect, so I tried to set my root view's alpha value, but it did not work.
And I set opaque to NO, but it still didn’t work. It looks just like a black screen:
My question is: Maybe it’s limited for Apple's app use only?

This used to work, but it was never documented, and apparently has been removed from more recent versions of iOS. You can use UIVisualEffectView to blur things in your own app, but you can’t make your app transparent so that you can see the device wallpaper. If you think Apple should add this feature for developers, you should file a bug.

When app get background, use the codes below:
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
[effectView setFrame:self.view.bounds];
[self.view addSubview:effectView];
ADDED
- (void)applicationWillResignActive:(UIApplication *)application {
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
[effectView setFrame:[[UIScreen mainScreen] bounds]];
[[[UIApplication sharedApplication] keyWindow] addSubview:effectView];
}
Tested and works.
Don't forget to remove the effectView when app become active.

Related

How can I create Visual effect to alert view similar to iOS default alerts?

I have created UIVisualEffectView and I like it much. But, I don't have any idea on how can I create iOS like alert view having blur effect.
Here is the screenshot which explains what I need.
Here is sample it may be help you
you can change BlurEffect type
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *backgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[self.view insertSubview:backgroundView atIndex:0];

Change Notification Content Extension background color

While developing Notification Content Extension I noticed, it's impossible to change background color to clear color.
I want it looks like background of weather standard app widget.
So, if I change background color of View to clear in IB or by code, it's become white without alpha.
You see that buttons with blurred background and white notification background looks awful. If you have some ideas, please tell me.
Tested on iPhone 6 Plus and iPhone 6s iOS 10 beta 3 and Xcode 8 beta 3.
you can try adding a UIBlurEffect like this:
self.view.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
blurEffectView.alpha = 0.5;
[self.view insertSubview:blurEffectView atIndex:0];
you can play with background color or with UIBlurEffectStyle to achieve exact thing that you like.

UIBlurEffect is always nil

I've been trying to add a blur effect to my app and upon debugging it using breakpoints, the UIBlurEffect variable is always nil.
Following is the code I am using:
UIBlurEffect *effect = [[UIBlurEffect alloc] init];
effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect: effect];
bluredView.frame = self.view.bounds;
[self.view addSubview:bluredView];
I have tried a couple different things, for example instead of alloc and init UIBlurEffect, directly using it as follows:
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
It is still always set to nil.
Is there an import I'm missing? I have imported UIKit in my .h file but 'effect' is always nil for some reason.
If anyone has experience the same, I would really appreciate it if you could share your experience.
Any help on the matter would be great!
Thanks in advance!
Are you running on iOS 7? UIBlurEffect is only available on iOS 8 and above.
These two Gits may help you, even I firstly didn't see they use UIBlurImage. Try them :)
LBBlurredImage
BTGlassScrollView

iOS 8 UIVisualEffect View with UIBlurEffect becomes opaque

I am trying to present a view with a blurred transparent background over an existing view. I am able to get the desired effect during the presentation animation, but once the blurred view is fully presented, it becomes opaque.
Here's how I am presenting it:
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;
[blurEffectView setOpaque:NO];
[self.view insertSubview:blurEffectView atIndex:0];
[blurEffectView setTranslatesAutoresizingMaskIntoConstraints:false];
}
In my blurred view, I have set the background color to clear color and opaque to NO. Any thoughts?
Note that any UIVisualEffectView with a UIBlurEffect will be opaque if the "Reduce Transparency" accessibility setting is on.
(Settings > General > Accessibility > Increase Contrast > Reduce Transparency)
(Which is what your are actually checking with your if (!UIAccessibilityIsReduceTransparencyEnabled()) statement.)
I wound up writing a custom presentation controller. Never found a way to do this with standard presentations.
In the view where I want the effect viewDidLoad:
//Custom Modal Presentation
[self setModalPresentationStyle:UIModalPresentationCustom];
//blur the controlContainerView
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:[self blurStyle]];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.controlContainerView.bounds;
[blurEffectView setOpaque:NO];
[self.controlContainerView insertSubview:blurEffectView atIndex:0];
[blurEffectView setTranslatesAutoresizingMaskIntoConstraints:false];
}
Invoking the above view:
//in .h
#property (nonatomic) id<UIViewControllerTransitioningDelegate> transitioningDelegate;
//In .m
BlurViewController *blurVC = [self.storyboard instantiateViewControllerWithIdentifier:#"blurView"];
_transitioningDelegate = [[MyCustomOverlayDelegate alloc] init];
[blurView setModalPresentationStyle:UIModalPresentationCustom];
[blurView setTransitioningDelegate:[self transitioningDelegate]];
[blurView setBlurStyle:UIBlurEffectStyleLight];
[self presentViewController: blurView animated:YES completion:nil];
You will also need to import the entire stack of presentation controller classes. For me, these were OverlayDelegate, OverlayTransitionAnimator, and OverlayPresentationController. This is where the real work is.
If you can, check out WWDC 2014 session 228 "A look inside presentation controllers". Custom presentations are covered about half-way through. It was what I used to base my custom stack on and reasonably straight forward.
From the documentation:
A UIBlurEffect object applies a blurring effect to the content layered behind a UIVisualEffectView.
So I think the problem is your clear backgroundColor. If you have some kind of content or coloring behind your UIVisualEffectView, it should work.
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
UIVisualEffectView *blurredView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
This simple code snippet does work for me. In the ViewController I want to show the blurred effect I just call [[self view] addSubView:blurredView]
Simply set the view controller which holds the blurred view like this:
myViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
It prevents optimisation which removes views from the view hierarchy which in turn makes the blurred view presented first and thus making it opaque.

Strange blur artefacts with UIVisualEffectView

I have a UIVisualEffectView which is causing some strange artefacts right when it appears. The UIVisualEffectView is added in code after the view loads because it's not available in iOS 7.
Look at the blurred text background over the street view image: http://s.swic.name/Z3UL
The blur takes a good 0.1 seconds to appear, and before that it's just a lower resolution background shining through like the blur hasn't been calculated yet.
Any idea what is going on? I'm adding the blur in awakeFromNib using this code
- (void)addBlurWithColor:(UIColor *)color andStyle:(UIBlurEffectStyle)style andVibrancy:(BOOL)vibrancy
{
if (UIDevice.supportsVisualEffects && NSClassFromString(#"UIVisualEffectView") && !UIAccessibilityIsReduceTransparencyEnabled()) {
self.backgroundColor = color;
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:style];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.bounds;
visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
NSArray *subviews = self.subviews;
[self addSubview:visualEffectView];
[self sendSubviewToBack:visualEffectView];
if (vibrancy) {
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
UIVisualEffectView *vibrancyEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
[vibrancyEffectView setFrame:self.bounds];
vibrancyEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
for (UIView *subview in subviews) {
[vibrancyEffectView.contentView addSubview:subview];
}
[[visualEffectView contentView] addSubview:vibrancyEffectView];
}
}
}
Edit: The video just has slow animations enabled, the transition is a regular push segue.
Edit2: I get the same strange behaviour if i just drag drop a "UIVisualEffectView with Blur" in Interface Builder, so the code above shouldn't be to blame.
Found the problem, when the view appears I'm reloading the tableview inside [UIView transitionWithView:...] which alters the alpha which apparently is a big no-no when it comes to UIVisualEffectViews!
According to UIVisualEffectView Documentation;
When using the UIVisualEffectView class, avoid alpha values that are
less than 1. Creating views that are partially transparent causes the
system to combine the view and all the associated subviews during an
offscreen render pass. UIVisualEffectView objects need to be combined
as part of the content they are layered on top of in order to look
correct. Setting the alpha to less than 1 on the visual effect view or
any of its superviews causes many effects to look incorrect or not
show up at all.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIVisualEffectView/index.html

Resources