IOS Screensaver animations

Source: Internet
Author: User

Objective


recently, the company did not project, we code farmers in the "slack" period, the director said to me to find an animation rendering engine, looking for a long time did not find the right, so he wrote a self-feeling more cool screensaver effect.
one, the control interface, the interface is not technical content, the main role is to control the animation in the end, such as the richness of animation color and animation speed. Warm tips, follow the prompts to fill in the corresponding numbers, I did not do cross-border treatment, if you crash, please do not look for me.
-(void) viewdidload {[Super viewdidload];    Self.view.backgroundColor = [Uicolor Whitecolor];        Self.title = @ "Set parameter";    UILabel *labelcolor = [[UILabel alloc] Initwithframe:cgrectmake (0, 30)];    Labelcolor.text = @ "Set color richness";    Labelcolor.backgroundcolor = [Uicolor Grouptableviewbackgroundcolor];            [Self.view Addsubview:labelcolor]; Set the range of R values UIView *VIEWR = [[UIView alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (labelcolor.frame) +10, SELF.VIEW.F    RAME.SIZE.WIDTH-20, 70)]; ViewR.layer.borderColor = [Uicolor Grouptableviewbackgroundcolor].    Cgcolor;    ViewR.layer.borderWidth = 1.0;    ViewR.layer.cornerRadius = 2.0;        [Self.view ADDSUBVIEW:VIEWR];    UILabel *title = [[UILabel alloc] Initwithframe:cgrectmake (5, 5, 200, 20)];    Title.text = @ "Please set the range of R values (0-255)";    Title.textcolor = [Uicolor Graycolor];    Title.font = [Uifont systemfontofsize:15.0];        [VIEWR Addsubview:title]; UILabel *min = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (title.frame) +10, 70, 25)];    Min.text = @ "min value:";    Min.textcolor = [Uicolor Graycolor];    Min.font = [Uifont systemfontofsize:17.0];        [VIEWR Addsubview:min]; TEXTFIELDMINR = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Min.frame), Cgrectgetminy (Min.frame), 50    , 25)];    TextFieldMinR.layer.borderWidth = 1.0f; TextFieldMinR.layer.borderColor = [Uicolor Graycolor].    Cgcolor;    TextFieldMinR.layer.cornerRadius = 2.0;    Textfieldminr.textalignment = Nstextalignmentcenter;        [VIEWR ADDSUBVIEW:TEXTFIELDMINR]; UILabel *max = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (textfieldminr.frame) +50, Cgrectgetmaxy (    Title.frame) +10, 70, 25)];    Max.text = @ "Maximum value:";    Max.textcolor = [Uicolor Graycolor];    Max.font = [Uifont systemfontofsize:17.0];        [VIEWR Addsubview:max]; TEXTFIELDMAXR = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Max.frame), Cgrectgetminy (Min.frame), 50    , 25)]; re>TFieldMaxR.layer.borderWidth = 1.0f; TextFieldMaxR.layer.borderColor = [Uicolor Graycolor].    Cgcolor;    TextFieldMaxR.layer.cornerRadius = 2.0;    Textfieldmaxr.textalignment = Nstextalignmentcenter;            [VIEWR ADDSUBVIEW:TEXTFIELDMAXR]; Set the range of G-values UIView *VIEWG = [[UIView alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (viewr.frame) +10, Self.view.fra    ME.SIZE.WIDTH-20, 70)]; ViewG.layer.borderColor = [Uicolor Grouptableviewbackgroundcolor].    Cgcolor;    ViewG.layer.borderWidth = 1.0;    ViewG.layer.cornerRadius = 2.0;    [Self.view ADDSUBVIEW:VIEWG];    UILabel *titleg = [[UILabel alloc] Initwithframe:cgrectmake (5, 5, 200, 20)];    Titleg.text = @ "Please set the range of G value (0-255)";    Titleg.textcolor = [Uicolor Graycolor];    Titleg.font = [Uifont systemfontofsize:15.0];        [VIEWG Addsubview:titleg];    UILabel *ming = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (titleg.frame) +10, 70, 25)];    Ming.text = @ "min value:";    Ming.textcolor = [Uicolor Graycolor]; Ming.font = [uifont systemfontofsize:17.0];        [VIEWG addsubview:ming]; textfieldming = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Ming.frame), Cgrectgetminy (MinG.frame),    50, 25)];    TextFieldMinG.layer.borderWidth = 1.0f; TextFieldMinG.layer.borderColor = [Uicolor Graycolor].    Cgcolor;    TextFieldMinG.layer.cornerRadius = 2.0;    Textfieldming.textalignment = Nstextalignmentcenter;        [VIEWG addsubview:textfieldming]; UILabel *maxg = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (textfieldming.frame) +50, Cgrectgetmaxy (    Titleg.frame) +10, 70, 25)];    Maxg.text = @ "Maximum value:";    Maxg.textcolor = [Uicolor Graycolor];    Maxg.font = [Uifont systemfontofsize:17.0];        [VIEWG ADDSUBVIEW:MAXG]; TEXTFIELDMAXG = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Maxg.frame), Cgrectgetminy (MinG.frame),    50, 25)];    TextFieldMaxG.layer.borderWidth = 1.0f; TextFieldMaxG.layer.borderColor = [Uicolor Graycolor].    Cgcolor; TextFieldMaxG.layer.corneRradius = 2.0;    Textfieldmaxg.textalignment = Nstextalignmentcenter;            [VIEWG ADDSUBVIEW:TEXTFIELDMAXG]; Set the range of B-values UIView *VIEWB = [[UIView alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (viewg.frame) +10, Self.view.fra    ME.SIZE.WIDTH-20, 70)]; ViewB.layer.borderColor = [Uicolor Grouptableviewbackgroundcolor].    Cgcolor;    ViewB.layer.borderWidth = 1.0;    ViewB.layer.cornerRadius = 2.0;        [Self.view ADDSUBVIEW:VIEWB];    UILabel *titleb = [[UILabel alloc] Initwithframe:cgrectmake (5, 5, 200, 20)];    Titleb.text = @ "Please set the range of B values (0-255)";    Titleb.textcolor = [Uicolor Graycolor];    Titleb.font = [Uifont systemfontofsize:15.0];        [Viewb Addsubview:titleb];    UILabel *minb = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (titleb.frame) +10, 70, 25)];    Minb.text = @ "min value:";    Minb.textcolor = [Uicolor Graycolor];    Minb.font = [Uifont systemfontofsize:17.0];        [Viewb ADDSUBVIEW:MINB]; TEXTFIELDMINB = [[Uitextfield alloc] Initwithframe:cgrEctmake (Cgrectgetmaxx (Minb.frame), Cgrectgetminy (Minb.frame), 50, 25)];    TextFieldMinB.layer.borderWidth = 1.0f; TextFieldMinB.layer.borderColor = [Uicolor Graycolor].    Cgcolor;    TextFieldMinB.layer.cornerRadius = 2.0;    Textfieldminb.textalignment = Nstextalignmentcenter;        [Viewb ADDSUBVIEW:TEXTFIELDMINB]; UILabel *MAXB = [[UILabel alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (textfieldminb.frame) +50, Cgrectgetmaxy (    Titleb.frame) +10, 70, 25)];    Maxb.text = @ "Maximum value:";    Maxb.textcolor = [Uicolor Graycolor];    Maxb.font = [Uifont systemfontofsize:17.0];        [Viewb ADDSUBVIEW:MAXB]; TEXTFIELDMAXB = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Maxb.frame), Cgrectgetminy (MinB.frame),    50, 25)];    TextFieldMaxB.layer.borderWidth = 1.0f; TextFieldMaxB.layer.borderColor = [Uicolor graycolor].<pre name= "code" class= "OBJC" > #import "AnimationView.h" @ Interface Animationview () @end @implementation animationview@synthesize minr,ming,minb; @synthesize MaxR, MAXG,MAXB; @synthesize suduzhi;-(void) viewdidload {[Super viewdidload];    i = 0;    j = 0;        Timenum = 1;       Self.view.backgroundColor = [Uicolor blackcolor]; Timer = [Nstimer Scheduledtimerwithtimeinterval:[suduzhi floatvalue] target:self selector: @selector (Drawcirle)    Userinfo:nil Repeats:yes];        }-(void) drawcirle{timenum = Timenum +1;        Calayer *wavelayer=[calayer layer];    if (Timenum <) {Wavelayer.frame = CGRectMake (self.view.center.x, SELF.VIEW.CENTER.Y, 10, 10);        } else if (timenum >100 && timenum <170) {wavelayer.frame = CGRectMake (i, i*2, 10, 10);    i = i +5; } else if (timenum >170 && timenum <240) {wavelayer.frame = CGRectMake (self.view.frame.size.width-        J, J*2, 10, 10);    j = J +5;        } else if (Timenum >240 && Timenum < +) {int x = (Arc4random ()%300) +20;        int y = (arc4random ()%500) +20; Wavelayer.frame = CGRectMake (x, Y, 10, 10); } else if (timenum>400) {[Timer invalidate];//stop Timer}//Set color int rMin = (int) [MinR inte    Gervalue];        int rMax = (int) [MaxR integervalue];    int gMin = (int) [MinG integervalue];        int gMax = (int) [Maxg integervalue];    int bmin = (int) [MINB integervalue];        int bmax = (int) [MAXB integervalue];    int rednum = (arc4random ()%rmax) + rMin;    int greennum = (arc4random ()%gmax) + gMin;        int bluenum = (arc4random ()%bmax) + bmin;        NSLog (@ "%d%d%d", rednum,greennum,bluenum);        Uicolor *color = [Uicolor colorwithred:rednum/255.0 green:greennum/255.0 blue:bluenum/255.0 alpha:1.0]; Wavelayer.bordercolor = color.        Cgcolor;    Wavelayer.borderwidth = 0.5;        Wavelayer.cornerradius = 5.0;    [Self.view.layer Addsublayer:wavelayer];        [Self scalebegin:wavelayer];        }-(void) Scalebegin: (Calayer *) alayer{float Maxscale;    if (Timenum <) {Maxscale = 50.0;   }else {maxscale = 20.0; } if (Alayer.transform.m11<maxscale) {if (alayer.transform.m11==1.0) {[Alayer settransform:                    Catransform3dmakescale (1.1, 1.1, 1.0)];        }else{[Alayer Settransform:catransform3dscale (Alayer.transform, 1.1, 1.1, 1.0)];    } [Self Performselector:_cmd withobject:alayer afterdelay:0.05]; }else [Alayer Removefromsuperlayer];} @end

Cgcolor; TextFieldMaxB.layer.cornerRadius = 2.0; Textfieldmaxb.textalignment = Nstextalignmentcenter; [Viewb ADDSUBVIEW:TEXTFIELDMAXB]; Set the speed of the animation UILabel *labelsudu = [[UILabel alloc] Initwithframe:cgrectmake (0, Cgrectgetmaxy (viewb.frame) +20, Self.view.frame.size.width, 25)]; Labelsudu.backgroundcolor = [Uicolor Grouptableviewbackgroundcolor]; Labelsudu.text = @ "Set the speed of animation"; [Self.view Addsubview:labelsudu]; UIView *viewsudu = [[UIView alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (labelsudu.frame) +10, SELF.VIEW.FRAME.SIZE.WIDTH-20, 70)]; ViewSudu.layer.borderColor = [Uicolor Grouptableviewbackgroundcolor]. Cgcolor; ViewSudu.layer.borderWidth = 1.0; ViewSudu.layer.cornerRadius = 2.0; [Self.view Addsubview:viewsudu]; UILabel *titlesudu = [[UILabel alloc] Initwithframe:cgrectmake (5, 5, 200, 20)]; Titlesudu.text = @ "Please set the range of speed values (0.1-0.5)"; Titlesudu.textcolor = [Uicolor Graycolor]; Titlesudu.font = [Uifont systemfontofsize:15.0]; [Viewsudu Addsubview:titlesudu]; UILabel *suduzhi = [[UILabelAlloc] Initwithframe:cgrectmake (Cgrectgetmaxy (titlesudu.frame) +10, 70, 25)]; Suduzhi.text = @ "Speed value:"; Suduzhi.textcolor = [Uicolor Graycolor]; Suduzhi.font = [Uifont systemfontofsize:17.0]; [Viewsudu Addsubview:suduzhi]; Textfieldsudu = [[Uitextfield alloc] Initwithframe:cgrectmake (Cgrectgetmaxx (Suduzhi.frame), Cgrectgetminy ( Suduzhi.frame), 50, 25)]; TextFieldSudu.layer.borderWidth = 1.0f; TextFieldSudu.layer.borderColor = [Uicolor Graycolor]. Cgcolor; TextFieldSudu.layer.cornerRadius = 2.0; Textfieldsudu.textalignment = Nstextalignmentcenter; [Viewsudu Addsubview:textfieldsudu]; UIButton *btn = [[UIButton alloc] Initwithframe:cgrectmake (Cgrectgetmaxy (viewsudu.frame) +50, SELF.VIEW.FRAME.SIZE.WIDTH-20, 35)]; Btn.backgroundcolor = [Uicolor Graycolor]; [Btn settitle:@ "Start animation" forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN]; }-(void) Btnclick: (ID) Sender {animationview *next = [[AnImationview alloc] init]; Next.minr = Textfieldminr.text; next.ming = Textfieldming.text; NEXT.MINB = Textfieldminb.text; NEXT.MAXR = Textfieldmaxr.text; Next.maxg = Textfieldmaxg.text; NEXT.MAXB = Textfieldmaxb.text; Next.suduzhi = Textfieldsudu.text; Determine if there is a value for filling in if (textFieldMinR.text.length >0 && textFieldMinG.text.length >0 && TextFieldMinB.text.length >0 && textFieldMaxR.text.length >0 && textFieldMaxG.text.length >0 && textFieldMinR.text.length >0 && textFieldMaxB.text.length >0 && TextFieldSudu.text.length >0) {[Self.navigationcontroller pushviewcontroller:next animated:yes];} else {Uialertview *alter = [[Uialertview alloc] initwithtitle:@ "Warm tip" message:@ "\ n you have content not filled in complete" delegate:self CancelButton title:@ "OK" otherbuttontitles:nil, nil]; [Alter show]; }} @end

Second, the animation implementation interface, this interface is dry.
#import "AnimationView.h" @interface Animationview () @end @implementation animationview@synthesize minr,ming,minb;@        synthesize maxr,maxg,maxb; @synthesize suduzhi;-(void) viewdidload {[Super viewdidload];    i = 0;    j = 0;        Timenum = 1;       Self.view.backgroundColor = [Uicolor blackcolor]; Timer = [Nstimer Scheduledtimerwithtimeinterval:[suduzhi floatvalue] target:self selector: @selector (Drawcirle)    Userinfo:nil Repeats:yes];        }-(void) drawcirle{timenum = Timenum +1;        Calayer *wavelayer=[calayer layer];    if (Timenum <) {Wavelayer.frame = CGRectMake (self.view.center.x, SELF.VIEW.CENTER.Y, 10, 10);        } else if (timenum >100 && timenum <170) {wavelayer.frame = CGRectMake (i, i*2, 10, 10);    i = i +5; } else if (timenum >170 && timenum <240) {wavelayer.frame = CGRectMake (self.view.frame.size.width-        J, J*2, 10, 10);    j = J +5; } else if (Timenum >240 && Timenum < () {int x = (Arc4random ()%300) +20;        int y = (arc4random ()%500) +20;    Wavelayer.frame = CGRectMake (x, Y, 10, 10); } else if (timenum>400) {[Timer invalidate];//stop Timer}//Set color int rMin = (int) [MinR inte    Gervalue];        int rMax = (int) [MaxR integervalue];    int gMin = (int) [MinG integervalue];        int gMax = (int) [Maxg integervalue];    int bmin = (int) [MINB integervalue];        int bmax = (int) [MAXB integervalue];    int rednum = (arc4random ()%rmax) + rMin;    int greennum = (arc4random ()%gmax) + gMin;        int bluenum = (arc4random ()%bmax) + bmin;        NSLog (@ "%d%d%d", rednum,greennum,bluenum);        Uicolor *color = [Uicolor colorwithred:rednum/255.0 green:greennum/255.0 blue:bluenum/255.0 alpha:1.0]; Wavelayer.bordercolor = color.        Cgcolor;    Wavelayer.borderwidth = 0.5;        Wavelayer.cornerradius = 5.0;    [Self.view.layer Addsublayer:wavelayer];        [Self scalebegin:wavelayer]; }-(void) Scalebegin: (Calayer *) alayer{float Maxscale;    if (Timenum <) {Maxscale = 50.0;    }else {maxscale = 20.0; } if (Alayer.transform.m11<maxscale) {if (alayer.transform.m11==1.0) {[Alayer settransform:c                    Atransform3dmakescale (1.1, 1.1, 1.0)];        }else{[Alayer Settransform:catransform3dscale (Alayer.transform, 1.1, 1.1, 1.0)];    } [Self Performselector:_cmd withobject:alayer afterdelay:0.05]; }else [Alayer Removefromsuperlayer];} @end

Third, look at the effect of it


IOS Screensaver animations

Related Article

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.