iOS development--Adding simple animation effects

Source: Internet
Author: User

Record a simple animation effect, write it yourself, very simple, just do the recording.

Attached to a demo:

Https://github.com/hgl753951/hglTest.git

The code is as follows:

1, prepare

BOOL _isopen;     * _btnarray;

2, specific code

-(void) initui{_btnarray=[[Nsmutablearray alloc]init];  for(intI=0; i<4; i++) {UIButton* BTN =[UIButton Buttonwithtype:uibuttontypecustom]; Btn.tag=i; Btn.frame= CGRectMake (260,420, +, +); [Btn setbackgroundimage:[uiimage imagenamed:[nsstring stringWithFormat:@"c_setting%d", (i+1)%4] ] [forstate:uicontrolstatenormal];        [Btn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside];        [Self.view ADDSUBVIEW:BTN];            [_btnarray ADDOBJECT:BTN]; }}-(void) Btnclick: (UIButton *) btn{//if it is not open    if(!_isopen) {        //Open Nine grid         for(inti =0; i < _btnarray.count; i++) {UIButton* Mybtn =[_btnarray objectatindex:i]; [UIView animatewithduration:0.3Animations:^{mybtn.frame= CGRectMake ( the+ (i%2)* -, -+ -* (i/2), +, +); } Completion:^(BOOL finished) {[UIView animatewithduration:0.3Animations:^{mybtn.frame= CGRectMake ( $+ (i%2)* -, the+ (i/2)* -, +, +);                             }];        }]; }            }    Else    {        //Close Nine grid         for(inti =0; i < _btnarray.count; i++) {UIButton* Mybtn =[_btnarray objectatindex:i]; [UIView animatewithduration:0.3Animations:^{mybtn.frame= CGRectMake ( the+ (i%2)* -, -+ -* (i/2), +, +); } Completion:^(BOOL finished) {[UIView animatewithduration:0.3Animations:^{mybtn.frame= CGRectMake (260,420, +, +);                             }];        }]; }} _isopen= !_isopen;}

The effect is as follows:

iOS development--Adding simple animation effects

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.