Using Cagradientlayer as a mask layer for Maskview
Description
Cagradientlayer can be used as an alpha matte for maskview use, both of which are very biased doors, but the side door does not mean that the function is not strong, we can use Cagradientlayer to create a very good animation effect, this blog, I would like to introduce a simple introduction how to Cagradientlayer and Maskview contact. Subsequent posts will expand and write better controls in succession.
Only the perfect UI interaction can be a great app for powerful apps, and I'm dedicated to researching and analysing Apple's most amazing but unpopular effects.
Source
////CAGradientView.h//Alphaview////Created by youxianming on 15/5/4.//Copyright (c) 2015 youxianming. All rights reserved.//#import<UIKit/UIKit.h>@interfaceCagradientview:uiview@property (nonatomic, strong) Nsarray*colors, @property (nonatomic, strong) Nsarray*locations; @property (nonatomic) cgpoint startPoint; @property (nonatomic) cgpoint endPoint;- (void) Alphatype;@end
////cagradientview.m//Alphaview////Created by youxianming on 15/5/4.//Copyright (c) 2015 youxianming. All rights reserved.//#import "CAGradientView.h"@interfaceCagradientview () {Cagradientlayer*_gradientlayer;}@end@implementationCagradientview/** * Modify the current view's backuplayer to Cagradientlayer * * @return Cagradientlayer class name*/+(Class) layerclass {return[Cagradientlayerclass];}-(Instancetype) initWithFrame: (CGRect) frame { self=[Super Initwithframe:frame]; if(self) {_gradientlayer= (Cagradientlayer *) Self.layer; } returnSelf ;}- (void) Alphatype {self.colors=@[[uicolor Clearcolor], [Uicolor blackcolor], [Uicolor Clearcolor]]; Self.locations= @[@(0.25), @(0.5), @(0.75)]; Self.startpoint= Cgpointmake (0,0); Self.endpoint= Cgpointmake (1,0);}/** * Override Setter,getter Method*/@synthesizecolors =_colors;- (void) Setcolors: (Nsarray *) Colors {_colors=colors; //convert color to CgcolorNsmutablearray *cgcolors =[Nsmutablearray array]; for(Uicolor *tmpinchcolors) { IDCgcolor = (__bridgeID) tmp. Cgcolor; [Cgcolors Addobject:cgcolor]; } //Set Colors_gradientlayer.colors =cgcolors;}-(Nsarray *) Colors {return_colors;}@synthesizeLocations =_locations;- (void) Setlocations: (Nsarray *) Locations {_locations=locations; _gradientlayer.locations=_locations;}-(Nsarray *) Locations {return_locations;}@synthesizeStartPoint =_startpoint;- (void) Setstartpoint: (cgpoint) startPoint {_startpoint=StartPoint; _gradientlayer.startpoint=StartPoint;}-(Cgpoint) startPoint {return_startpoint;}@synthesizeEndPoint =_endpoint;- (void) setEndPoint: (cgpoint) endPoint {_endpoint=EndPoint; _gradientlayer.endpoint=EndPoint;}-(Cgpoint) endPoint {return_endpoint;}@end
////VIEWCONTROLLER.M//Alphaview////Created by youxianming on 15/5/4.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ViewController.h"#import "CAGradientView.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //Add a mask to the viewUiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake ( +, +, $, $)]; Imageview.image= [UIImage imagenamed:@"Base"]; [Self.view Addsubview:imageview]; Cagradientview*gradientview =[[Cagradientview alloc] initWithFrame:imageView.bounds]; [Gradientview Alphatype]; Imageview.maskview=Gradientview; //control GroupUiimageview *baseimageview = [[Uiimageview alloc] Initwithframe:cgrectmake ( +, ++ $+ +, $, $)]; Baseimageview.image= [UIImage imagenamed:@"Base"]; [Self.view Addsubview:baseimageview];}@end
Simple analysis
Using Cagradientlayer as a mask layer for Maskview