Implements an animation of a view moving from the top to the bottom and converts RGB values to colors

Source: Internet
Author: User

@ Interface timingcurveviewcontroller: uiviewcontroller {
Iboutlet uiimageview * basketball;
}

-(Void) touchesended :( nsset *) touches withevent :( uievent *) event {

[Uiview beginanimations: @ "movement" context: Nil];
[Uiview setanimationcurve: uiviewanimationcurveeasein]; // <label id = "code. timingcurve. easein"/>
[Uiview setanimationduration: 1.0f];
[Uiview setanimationrepeatcount: 3];
[Uiview setanimationrepeatautoreverses: Yes];
Cgpoint center = Basketball. Center;
If (center. Y> 85.0f ){
Center. Y-= 295.0f;
Basketball. Center = center;
} Else {
Center. Y + = 295.0f;
Basketball. Center = center;
}
[Uiview commitanimations];

}

-(Void) viewdidload {
[Super viewdidload];
Self. View. backgroundcolor = [self colorwithrgbhexstring: @ "# abcdef"];
}

-(Uicolor *) colorwithrgbhexstring :( nsstring *) rgbcolor {
Nsstring * cstring = rgbcolor;

// Remove spaces and uppercase nscharactersetwhitespaceandnewlinecharacterset

Cstring = [[cstring stringbytrimmingcharactersinset: [nscharacterset whitespaceandnewlinecharacterset] uppercasestring];

If ([cstring length] <6 ){

// Returns the default color.

Return [uicolor redcolor];

}

If ([cstring hasprefix: @ "0x"]) {

Cstring = [cstring substringfromindex: 2];

} Else if ([cstring hasprefix: @ "#"]) {

Cstring = [cstring substringfromindex: 1];

}

If ([cstring length]! = 6 ){

// Returns the default color.

Return [uicolor redcolor];

}

Nsange range;

Range. Length = 2;

Range. Location = 0;

Nsstring * rstring = [cstring substringwithrange: range];

Range. Location = 2;

Nsstring * gstring = [cstring substringwithrange: range];

Range. Location = 4;

Nsstring * bstring = [cstring substringwithrange: range];



Unsigned int R, G, B;

[[Ns1_scannerwithstring: rstring] scanhexint: & R];

[[Ns1_scannerwithstring: gstring] scanhexint: & G];

[[Ns1_scannerwithstring: bstring] scanhexint: & B];



Return [uicolor colorwithred :( float) r/255.0 green :( float) g/255.0 blue :( float) B/255.0 ALPHA: 1.0f];
}

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.