3

我有一个白色的图像按钮。当我点击时,它应该通过从下到上的动画变成黄色按钮图像,如果我再次点击黄色按钮图像,它必须从上到下动画并变成白色图像按钮图像。

这是我尝试过的:

    float originalY = btn.frame.origin.y; 
    float originalH = btn.bounds.size.height;

    [UIView animateWithDuration:3.0f delay:1.0f     options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{

    btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);

    [btn setBackgroundImage:[UIImage imageNamed:@"yellowimg.png"] forState:UIControlStateNormal];

    [btn setTitleColor:[[UIColor alloc]initWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];

    }    
    completion:^(BOOL finished) {
        }];
4

1 回答 1

1
btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);

此方法将使您的按钮带有height = 0. 如果你想卷曲(翻转)你的按钮并拥有从第一个出现的“新”按钮,我知道你应该使用类似的东西

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstView cache:YES];
[firstView addSubview:secondView];
[UIView commitAnimations];
于 2012-11-07T14:26:36.917 回答