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 に答える