Apply a mask to a UIView to simulate a glass shimmer - ios

My base image is a complex shape with multiple colors and an alpha background.
My shimmer effect is a white slanted gradient with an alpha background.
My goal is to animate the shimmer image over top of the base image, but make the alpha values of of the shimmer match those of the base image.
I've only used layer masks to hide areas based on the color, not to both show AND hide parts of an image. Will I need to create multiple masks to achieve this? A white version of my base image that will show through the masked shimmer image, all on top of my colored base image?

Since your shimmer effect is created by moving a single image/layer over a base image, you only need one mask in the shape of the non-alpha values in your base image. You will likely need to use a container view for your shimmer image view/layer that you overlay onto of the base image, then set the image mask on the container.

Related

How to ensure a UIView with a transform fills a CGRect?

I have a view UIView that by default has a UIImageView (the blue square in the included image) that is centered in this main view (the gray square in the included image). The main view has an added CALayer that serves as a border (window or mask — the yellow rectangle in included image) through which the image can be seen. The user uses gesture recognizers to pan (translate), pinch (scale), and rotate the image view's transform, but I'd like to give them the option of transforming the image so it completely fills the yellow border (all four corners), much the same way the iOS crop tool does (see attached gif). I've tried to figure out how I can calculate the correct scale factor, but now I'm wondering — is there some simple formula or function that can help me solve this problem?

Stretch image border uniformly and leave center of image unstretched on iOS

Is it possible to achieve the same thing on iOS as on Android with this 9-patch file?
Result should be something like this. The flower is something on the background. Then I want to apply the gray overlay with transparent (see through, not stretched) logo in the center.
(the file is not a valid 9-patch, because of wider patch areas, but that is only for question clarity)
So basically I'd like to overlay the screen with this semi-transparent gray color and in the center would be unstretched logo - kind of cut-off from the overlay. (Notice that logo in image is completely transparent)
I tried to use image slices, but I can't define multiple slices per dimension, so just one border is resizing.
I'd like to avoid tile-ing the background from multiple views.

ios - How to do the clipping mask effect using the two images

Am having the mask image and the normal image i want to do the exact clipping mask effect and want to set that image to the UIImageView.
In this PIP Camera app they did this
https://itunes.apple.com/in/app/hua-zhong-hua-xiang-ji-nice/id521922264?mt=8
And i tried this
How to Mask an UIImageView
exactly what they suggest but no luck
Could anyone here give an idea of how we do that?

CSS Masking in iOS

I have an image in my iOS app. I want to use css masking technique to achieve the same image but with colors. The 1st image is the original image and the 2nd image is the output image that is required. How can i achieve it in iOS :
The drawing system on iOS is called Quartz 2D. Here's the documentation:
https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_overview/dq_overview.html
You will be able to use the shape of your image as a clipping path and then draw a gradient.
Alternatively, a simpler way is to draw a simple gradient with a CAGradientLayer and then mask the layer; see the documentation on CALayer and CAGradientLayer.

How to apply a soft shaped shadow to graphics which have transparent areas in them?

Normally I'm using CALayer shadowRadius, but now I also need to use UIImage and apply shaped shadows to it based on the content in the image.
For example when I have a layer with text in it and I set a shadow, it works automatically on the text and not just on the rectangle of the layer.
In Photoshop this is known as "layer style" and it automatically works based on the shape of the image content.
I am afraid that I need to implement some Harvard-Stanford-MIT-NASA kind of hardcore logic to apply a shadow on a "shaped image", i.e. an image of an round icon where the areas around the icon are fully transparent.
I'm able to manipulate images on a per-pixel level as I'm doing this already to draw charts, so if there was an open-sourced implementation of some fantastic algorithms this would be fantastic. And if not: How does this basically work? My guess is I would "just" try to blur a grayscaled version of my image somehow and then overlay it with the non-blurred version.
My guess is I would "just" try to blur a grayscaled version of my image somehow and then overlay it with the non-blurred version.
That's pretty much it, actually. Except instead of blurring a greyscaled version of the image, blur a solid-colored version of the image (i.e. keep the alpha channel, but make all pixels black). Although CALayer's shadowing should do this already for you.
If your images are already composited onto a background (i.e. without real transparency), you have a harder problem as you first need to "remove" the background before you can have the shape of the object in order to generate the shadow.

Resources