thu*_*nja 6 objective-c uiimageview uiimage
我想我想要做的事情很简单,但我似乎无法弄明白.我知道如何使用UIImageView在UIImage上应用渐变,但这不是我想要的.我想要做的是,在保持图像边界的同时,淡出UIImage的上半部分,使其完全透明.我希望能够看到UIImage背后的视图,图像的下半部分仍然完全可见(不透明).
有任何想法吗?任何帮助将不胜感激.
Noa*_*oon 11
最简单的方法是使用CAGradientLayer作为图层蒙版 - 换句话说,使用其不透明度来确定它附加到的图层的不透明度.这些方面的东西应该可以解决问题:
CALayer *imageViewLayer = theImageView.layer;
CAGradientLayer *maskLayer = [CAGradientLayer layer];
maskLayer.colors = @[ (id)([UIColor blackColor].CGColor), (id)([UIColor clearColor].CGColor) ]; // gradient from 100% opacity to 0% opacity (non-alpha components of the color are ignored)
// startPoint and endPoint (used to position/size the gradient) are in a coordinate space from the top left to bottom right of the layer: (0,0)–(1,1)
maskLayer.startPoint = CGPointMake(0, 0.5); // middle left
maskLayer.endPoint = CGPointMake(0, 0); // top left
maskLayer.frame = imageViewLayer.bounds; // line it up with the layer it’s masking
imageViewLayer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3308 次 |
| 最近记录: |