使随机UIButton动画突出显示然后回到正常状态

时间:2014-08-12 14:30:48

标签: ios objective-c xcode random uibutton

我首先要生成以下代码来生成随机按钮。 然后我想通过动画将按钮从突出显示更改为正常状态。 我可以知道如何修改我的代码吗?

 >         NSMutableArray* rand_btns = [[NSMutableArray alloc] initWithObjects:
    > A111,A222,A333,A444,A555,B111,B222,B333,B444,B555,C111,C222,C333,C444,C555,D111,D222,D333,D444,D555,nil];
    >         int randomTag =  arc4random() % 20;
    >         int randomTag2 =  arc4random() % 20;
    >         int randomTag3 =  arc4random() % 20;
    >         int randomTag4 =  arc4random() % 20;
    >         int randomTag5 =  arc4random() % 20;
    >         int randomTag6 =  arc4random() % 20;
    >         int randomTag7 =  arc4random() % 20;
    > 
     [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            [UIView setAnimationDelay:1.0];
        > [[rand_btns objectAtIndex:randomTag]

  setSelected:NO];        
    > NSLog(@"%d",randomTag);
    >         
    >         [[rand_btns objectAtIndex:randomTag2] setSelected:NO];
    >         NSLog(@"%d",randomTag2);
    >         [[rand_btns objectAtIndex:randomTag3]  setSelected:NO];
    >         NSLog(@"%d",randomTag3);
    >         [[rand_btns objectAtIndex:randomTag4]  setSelected:NO];
    >         NSLog(@"%d",randomTag4);
    >         [[rand_btns objectAtIndex:randomTag5]  setSelected:NO];
    >         NSLog(@"%d",randomTag5);
    >         [[rand_btns objectAtIndex:randomTag6]  setSelected:NO];
    >         NSLog(@"%d",randomTag6);
    >         [[rand_btns objectAtIndex:randomTag7]  setSelected:NO];
    >         
    >         NSLog(@"%d",randomTag7);

 [UIView commitAnimations];

1 个答案:

答案 0 :(得分:0)

你尝试过这样的动画:

 [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//there are other options which might be better for you
// insert here what you want to change.

        [[rand_btns objectAtIndex:randomTag]setSelected:NO];

//completion is a block, if you want to add anything.
    } completion:NULL];