Sample code
-(void) Viewdidload {
[Super Viewdidload];
[Self creatlayer];
[Self creattext];
[Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (change) userinfo:nil Repeats:yes];
}
-(void) Creatlayer
{
Calayer *left = [Calayer layer];
Left.frame = CGRectMake (100, 100, 200, 50);
Left.backgroundcolor = [Uicolor Bluecolor]. Cgcolor;
[Self.view.layer Addsublayer:left];
Self.left = left;
Calayer *right = [Calayer layer];
Right.frame = CGRectMake (100, 100, 200, 50);
Right.backgroundcolor = [Uicolor Redcolor]. Cgcolor;
[Self.view.layer Addsublayer:right];
Self.right = right;
}
-(void) Creattext
{
UILabel * Leftlabel =[[uilabel alloc]initwithframe:cgrectmake (100, 200, 200, 50)];
Leftlabel.text = @ "test test for testing";
Leftlabel.textcolor = [Uicolor Redcolor];
Leftlabel.textalignment = Nstextalignmentcenter;
[Self.view Addsubview:leftlabel];
Self.leftlabel = Leftlabel;
UILabel * Rightlabel =[[uilabel alloc]initwithframe:cgrectmake (100, 200, 200, 50)];
Rightlabel.text = @ "test test for testing";
Rightlabel.textcolor = [Uicolor Bluecolor];
Rightlabel.textalignment = Nstextalignmentcenter;
[Self.view Addsubview:rightlabel];
Self.rightlabel = Rightlabel;
}
-(void) Change
{
Self.bili = Arc4random ()%100;
Self.left.mask = [Calayer layer];
Self.left.mask.backgroundColor = [[Uicolor blackcolor] cgcolor];
Self.left.mask.frame = CGRectMake (0, 0, 100+self.bili, 50);
Self.right.mask = [Calayer layer];
Self.right.mask.backgroundColor = [[Uicolor blackcolor] cgcolor];
Self.right.mask.frame = CGRectMake (100+self.bili, 0, 100-self.bili, 50);
Self.leftLabel.layer.mask = [Calayer layer];
Self.leftLabel.layer.mask.backgroundColor = [[Uicolor blackcolor] cgcolor];
Self.leftLabel.layer.mask.frame = CGRectMake (0, 0, 100+self.bili, 50);
Self.rightLabel.layer.mask = [Calayer layer];
Self.rightLabel.layer.mask.backgroundColor = [[Uicolor blackcolor] cgcolor];
Self.rightLabel.layer.mask.frame = CGRectMake (100+self.bili, 0, 100-self.bili, 50);
}
The same is true of the Kvnmaskedpagecontrol principle:
Http://www.oschina.net/p/kvnmaskedpagecontrol/similar_projects?lang=0&sort=view&p=1
IOS makes seamless transitions with mask from layers