Page Turn effect

Source: Internet
Author: User

Create a new PageView integrated UIView:

#import "pageView.h"#import<CoreGraphics/CoreGraphics.h>@interfacePageView () @property (nonatomic,strong) Cagradientlayer*Leftshadowlayer, @property (nonatomic,strong) Cagradientlayer*Rightshadowlayer, @property (nonatomic,strong) Uiimageview*Leftimageview, @property (nonatomic,strong) Uiimageview*Rightimageview, @property (nonatomic) Nsuinteger initiallocation; @property (nonatomic,strong) Uiimageview*Rightbackview;@end@implementationPageView-(void) awakefromnib{[self config];}-(void) config{UIImage* image = [UIImage imagenamed:@"Raindrops"]; Self.leftimageview=[[Uiimageview alloc]init]; Self.rightimageview=[[Uiimageview alloc]init]; Self.leftImageView.userInteractionEnabled=YES; Self.rightImageView.userInteractionEnabled=YES; Self.leftImageView.frame= CGRectMake (0,0, Cgrectgetwidth (self.bounds)/2, Cgrectgetheight (self.bounds)); Self.rightImageView.layer.anchorPoint= Cgpointmake (0,0.5); Self.rightImageView.frame= CGRectMake (Cgrectgetmidx (self.bounds),0, Cgrectgetwidth (self.bounds)/2, Cgrectgetheight (self.bounds)); Self.leftImageView.image=[self clipimagewithimage:image isleftimage:yes]; Self.rightImageView.image=[self clipimagewithimage:image isleftimage:no]; Self.leftImageView.layer.mask=[self getcornerridusmashwithisleft:yes Rect:self.leftImageView.bounds]; Self.rightImageView.layer.mask=[self getcornerridusmashwithisleft:no Rect:self.rightImageView.bounds]; Self.rightbackview=[[Uiimageview alloc]init]; Self.rightBackView.frame=Self.rightImageView.bounds; Self.rightBackView.image=[self getblurandreversalimage:[self clipimagewithimage:image isleftimage:no]; Self.rightBackView.alpha=0;        [Self.rightimageview AddSubview:self.rightBackView]; Self.leftshadowlayer=[Cagradientlayer layer]; Self.leftShadowLayer.opacity=0; Self.leftShadowLayer.colors= @[(ID) [Uicolor Clearcolor]. Cgcolor, (ID) [Uicolor Blackcolor].    Cgcolor]; Self.leftShadowLayer.frame=Self.leftImageView.bounds; Self.leftShadowLayer.startPoint= Cgpointmake (1,1); Self.leftShadowLayer.startPoint= Cgpointmake (0,1);        [Self.leftImageView.layer AddSublayer:self.leftShadowLayer]; Self.rightshadowlayer=[Cagradientlayer layer]; Self.rightShadowLayer.opacity=0; Self.rightShadowLayer.colors= @[(ID) [Uicolor Clearcolor]. Cgcolor, (ID) [Uicolor Blackcolor].    Cgcolor]; Self.rightShadowLayer.frame=Self.rightImageView.bounds; Self.rightShadowLayer.startPoint= Cgpointmake (0,1); Self.rightShadowLayer.startPoint= Cgpointmake (1,1);    [Self.rightImageView.layer AddSublayer:self.rightShadowLayer];    [Self addSubview:self.leftImageView];    [Self addSubview:self.rightImageView]; Self.rightImageView.layer.transform= [Self Gettransform3dwithangle:0]; Uipangesturerecognizer* Pan =[[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (Panhandle:)]; [Self.rightimageview Addgesturerecognizer:pan];}-(Catransform3d) Gettransform3dwithangle: (cgfloat) angle{Catransform3d transform=catransform3didentity; TRANSFORM.M34=4.5/- -; Transform= Catransform3drotate (Transform,angle,0,1,0); returntransform;}-(UIImage *) Clipimagewithimage: (UIImage *) Image isleftimage: (BOOL) isleft{cgrect imagerect= CGRectMake (0,0, image.size.width/2, Image.size.height); if(!isleft) {imagerect.origin.x= image.size.width/2; } cgimageref imgref=Cgimagecreatewithimageinrect (image.    Cgimage, Imagerect); UIImage* Clipimage =[UIImage Imagewithcgimage:imgref];    Cgimagerelease (IMGREF); returnclipimage;}-(Cashapelayer *) Getcornerridusmashwithisleft: (BOOL) isleft Rect: (cgrect) rect{Cashapelayer* Layer =[Cashapelayer layer]; Uirectcorner Corner= Isleft? Uirectcornertopleft| Uirectcornerbottomleft:uirectcornertopright|Uirectcornerbottomright; Layer.path= [Uibezierpath bezierpathwithroundedrect:rect byroundingcorners:corner Cornerradii:cgsizemake (Ten,Ten)].    Cgpath; returnlayer;}-(void) Panhandle: (Uipangesturerecognizer *) pan{cgpoint Location=[Pan locationinview:self]; if(Pan.state = =Uigesturerecognizerstatebegan) {self.initiallocation=location.x; } NSLog (@"y:%@", [Self.rightImageView.layer Valueforkeypath:@"TRANSFORM.ROTATION.Y"]); NSLog (@"x:%@", [Self.rightImageView.layer Valueforkeypath:@"transform.rotation.x"]); if([[Self.rightImageView.layer Valueforkeypath:@"TRANSFORM.ROTATION.Y"] Floatvalue] >-m_pi_2&& ([[Self.rightImageView.layer Valueforkeypath:@"transform.rotation.x"] Floatvalue]! =0) {NSLog (@"------------%@", [Self.rightImageView.layer Valueforkeypath:@"TRANSFORM.ROTATION.Y"]); Self.rightBackView.alpha=1; Self.rightShadowLayer.opacity=0; CGFloat opacity= (location.x-self.initiallocation)/(Cgrectgetwidth (Self.bounds)-self.initiallocation); Self.leftShadowLayer.opacity=fabs (opacity); }    Else if([[[Self.rightImageView.layer Valueforkeypath:@"TRANSFORM.ROTATION.Y"] Floatvalue] >-m_pi_2) && ([[Self.rightImageView.layer Valueforkeypath:@"TRANSFORM.ROTATION.Y"] floatvalue]<0) && ([[Self.rightImageView.layer Valueforkeypath:@"transform.rotation.x"] floatvalue] = =0) ) {Self.rightBackView.alpha=0; CGFloat opacity= (location.x-self.initiallocation)/(Cgrectgetwidth (Self.bounds)-self.initiallocation); //self.rightShadowLayer.opacity = 0;Self.rightShadowLayer.opacity =fabs (Opacity) *0.5 ; Self.leftShadowLayer.opacity=fabs (Opacity) *0.5; }    if([self islocation:location inview:self]) {cgfloat conversiofactor= m_pi/(Cgrectgetwidth (self.bounds)-self.initiallocation); Self.rightImageView.layer.transform= [Self Gettransform3dwithangle: (location.x-self.initiallocation) *Conversiofactor]; }    Else{pan.enabled=NO; Pan.enabled=YES; }    if(pan.state = = uigesturerecognizerstateended| | Pan.state = =uigesturerecognizerstatecancelled)    {        ; }}-(BOOL) Islocation: (cgpoint) Location InView: (UIView *) view{if((location.x>0&& location.x<cgrectgetwidth (view.frame) && (location.y>0&&location.y<cgrectgetheight (view.frame))) {        returnYES; }    Else    {        returnNO; }}-(UIImage *) Getblurandreversalimage: (UIImage *) image{Cicontext* Context =[Cicontext Contextwithoptions:nil]; Ciimage* Inputimage =[Ciimage imagewithcgimage:image.    Cgimage]; Cifilter* Filter = [Cifilter filterwithname:@"Cigaussianblur"];    [Filter Setvalue:inputimage Forkey:kciinputimagekey]; [Filter Setvalue:[nsnumber numberwithfloat:10.0f] Forkey:@"Inputradius"]; Ciimage* result =[Filter Valueforkey:kcioutputimagekey]; Result= [Result Imagebyapplyingtransform:cgaffinetransformmaketranslation (-1,1)]; Cgimagerefref=[Context Createcgimage:result fromrect:[inputimage extent]; UIImage* Returnimage = [UIImage imagewithcgimage:ref]; Cgimagerelease (ref); returnreturnimage;}@end

In VC inside will this pageview reality can be, slide picture can see the effect of the page turn ...

Page Turn effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.