如果单击按钮,如何在正面翻转带有标签的视图和背面的另一个标签?看起来像下图的东西。
创造这种效果的逻辑是什么?
由于
编辑:
对于这种混乱感到抱歉但请注意,我只是在谈论一个不是ViewControllers的视图,这种效果会在同一个viewController中发生。我更新了图片,以反映我所说的视图是主视图中的子视图。
答案 0 :(得分:2)
我也有类似的情况,点击ViewController1
上的按钮我必须转移到另一个ViewController2
。我用过这段代码,
//code this in ViewController1
-(IBAction)flipView:(id)sender
{
ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1.0];
[[self navigationController] pushViewController:view2 animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[view2 release];
}
//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[[self navigationController] popViewControllerAnimated:YES];
[UIView commitAnimations];
}
但是在这段代码中,我使用了2个类,如果它对你没问题,请使用此代码。希望它能在一定程度上解决你的问题。
答案 1 :(得分:1)
你可以做的是使用两个UIView
,一个用于第一面,一个用于第二面。
显示第一个视图,隐藏第二个视图,并将第二个视图的帧设置为宽度为0.
然后,当您的第一个视图可见时,为其框架设置动画,使其宽度等于0.隐藏第一个视图,取消隐藏第二个视图,并将第二个视图的框架设置为所需框架的动画。
编辑:如果您的视图中有标签,这似乎无法正常工作,因为这是2D翻转。对于那个很抱歉。 @ Maverick的回答可以很好地适用于你的情况。
答案 2 :(得分:1)
在viewController中调用此方法,viewController视图翻转和viewController生命周期方法调用,只需更改要在其中显示的UIImageView的图像 - (void)viewdidload方法。
[UIView beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Please vote up if you find it helping