我试图通过单击按钮在一个屏幕上翻转两个视图,即我想同时拥有多个动画(例如:iPhone音乐播放器,其中按钮和视图同时翻转)
p.s-i不想一个接一个地制作视图,它应该一起完成
修改
这是我使用的代码,请帮帮我
[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];
答案 0 :(得分:3)
假设bgView1
和bgView2
是要翻转的视图,如下所示;你应该能够一个接一个地放置动画代码,它应该都可以正常工作。请参阅下面的示例
-(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];
}
答案 1 :(得分:1)
只需使用块动画,它应该没有任何问题。
[UIView animateWithDuration:myDuration
animations:^{
<animation 1 code>;
<animation 2 code>;
}];