简体   繁体   English

带动画的UIButton图像按钮

[英]UIButton image button with animation

I have a white image button. 我有一个白色图像按钮。 when I click, it should change into yellow button image by animating from Bottom to top and if I click yellow button image again it must animate top to bottom and change as white image button image. 当我点击时,它应该通过从底部到顶部动画来变为黄色按钮图像,如果我再次单击黄色按钮图像,它必须从上到下动画并更改为白色图像按钮图像。

This is what I tried: 这是我试过的:

    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) {
        }];
btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);

This method will make your button with height = 0 . 此方法将使您的按钮height = 0 If you want to curl (flip) your button and to have 'new' button which appeared from the first as I know you should use something like that 如果你想卷曲(翻转)你的按钮,并从第一个出现'新'按钮,我知道你应该使用类似的东西

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstView cache:YES];
[firstView addSubview:secondView];
[UIView commitAnimations];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM