簡體   English   中英

帶動畫的UIButton圖像按鈕

[英]UIButton image button with animation

我有一個白色圖像按鈕。 當我點擊時,它應該通過從底部到頂部動畫來變為黃色按鈕圖像,如果我再次單擊黃色按鈕圖像,它必須從上到下動畫並更改為白色圖像按鈕圖像。

這是我試過的:

    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);

此方法將使您的按鈕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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM