【问题标题】:how to flip two views at once?如何一次翻转两个视图?
【发布时间】:2012-04-03 19:28:35
【问题描述】:

我试图通过单击一个按钮在一个屏幕中翻转两个视图,即我想同时拥有多个动画(例如:按钮和视图同时翻转的 iPhone 音乐播放器)

p.s-我不想一个接一个地动画视图,应该一起做

编辑

这是我使用的代码,请帮帮我

[UIView beginAnimations:nil context:nil];
[UIView animateWithDuration:0.8 animations:^{

    if (viewDisplay) 

    {

        [fareView removeFromSuperview];

        [containerView addSubview:mapView];

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonView cache:YES];

        viewDisplay = FALSE;

        swapLabel.text = @"Fare View";

        [mapOrFare setImage:[UIImage imageNamed:@"original_icon.png"] forState:UIControlStateNormal];

    }

    else

    {

        [mapView removeFromSuperview];

        [containerView addSubview:fareView];

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:YES];

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonView cache:YES];

        viewDisplay = TRUE;

        swapLabel.text = @"Map View";

        [mapOrFare setImage:[UIImage imageNamed:@"Map.png"] forState:UIControlStateNormal];

    }

}];

[UIView commitAnimations];

【问题讨论】:

  • 我尝试使用 [UIView beginAnimation..] 为两个子视图设置动画。 . [UIView commitAnimation] 块,但只有一个视图是动画的。另一个只是出现。

标签: iphone objective-c animation view flip


【解决方案1】:

假设bgView1bgView2是要翻转的视图,如下图;您应该能够将动画师代码一个接一个地放置,并且一切正常。看下面的例子,

-(void)flipViews {

    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView1 cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];

    [bgView1 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

    [UIView commitAnimations];


    context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView2 cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];

    [bgView2 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

    [UIView commitAnimations];

}

【讨论】:

    【解决方案2】:

    只需使用块动画,它应该没有问题。

    [UIView animateWithDuration:myDuration
        animations:^{
            <animation 1 code>;
            <animation 2 code>;
    }];
    

    【讨论】:

    • 没用,因为动画代码是关键,这个代码示例的动画代码是什么样子的??
    猜你喜欢
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    相关资源
    最近更新 更多