Iphone - focus effect (like UIAlertView)

I know that the title of my question is so bad, but I don’t know how to describe it.

When the UIAlertView appears, everything else on the screen (except for the UIAlertView) becomes a little darker, but you can see it. I call this the focus effect because you will clearly and clearly know that UIAlertView is now the focus.

So how can I implement such a focusing effect?

thanks

+6
source share
4 answers

Just add a translucent view below the view you want to “focus on”. A simple example:

UIView *shieldView = [[[UIView alloc] initWithFrame:myView.bounds] autorelease]; shieldView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7]; [myView.superview insertSubview:shieldView belowSubview:myView]; 

UIAlertView actually uses a radial gradient image instead of a simple color to highlight the center of the view.

+4
source

I know this post is a bit outdated, but I thought it might help someone.

Use this code to generate a radial gradient background:

 - (UIImage *)radialGradientImage:(CGSize)size start:(float)start end:(float)end centre:(CGPoint)centre radius:(float)radius{ UIGraphicsBeginImageContextWithOptions(size, YES, 1); size_t count = 2; CGFloat locations[2] = {0.0, 1.0}; CGFloat components[8] = {start, start, start, 1.0, end, end, end, 1.0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef grad = CGGradientCreateWithColorComponents (colorSpace, components, locations, count); CGColorSpaceRelease(colorSpace); CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), grad, centre, 0, centre, radius, kCGGradientDrawsAfterEndLocation); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); CGGradientRelease(grad); UIGraphicsEndImageContext(); return image;} 

Define the gradient in the .h file like this:

 UIImageView *gradient; 

Name your gradient as follows:

 - (void)addGradient{ CGSize size = self.view.bounds.size; CGPoint centre = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2); float startColor = 1.0f; float endColor = 0.0f; float radius = MIN(self.view.bounds.size.width/4, self.view.bounds.size.height/4); gradient = [[UIImageView alloc] initWithImage:[self radialGradientImage:size start:startColor end:endColor centre:centre radius:radius]]; [gradient setBackgroundColor:[UIColor clearColor]]; [gradient setUserInteractionEnabled:YES]; [gradient setAlpha:0.6f]; [self.view addSubview:gradient];} 
+4
source

UIAlertView works like this. It disappears in the alpha mask image to wash the background. Once this animation is complete, it will begin the rebound dialog animation.

To play it, you first need to create an alpha mask with a “bright spot” where your dialogue will end and disappear. Then use animation (multiple) frames to get a bounce effect.

Read more here: Creating an animation of pop music similar to the presentation of UIAlertView

+2
source

To do this better than "bad", you could ...

  • create a UIView in the nib (the easiest way is if the part of your code where you need the effect already uses the thread), and then add the translucent graphics (with the focus effect) to this view.

  • connect UIView in nib to IBOutlet

  • disappears in the graph using animation in the view hierarchy (omz example shows this)

0
source

Source: https://habr.com/ru/post/888018/


All Articles