如何翻转正面带有标签而背面带有另一个标签的视图 - 参见图片

Posted

技术标签:

【中文标题】如何翻转正面带有标签而背面带有另一个标签的视图 - 参见图片【英文标题】:How to flip a view with a label on the front side and another label on the back side - see image 【发布时间】:2014-03-21 12:47:21 【问题描述】:

当单击按钮时,如何翻转正面带有标签而背面带有另一个标签的视图?如下图所示。

产生这种效果的逻辑是什么?

谢谢

编辑:

很抱歉造成混淆,但请注意,我只是在谈论视图而不是 ViewController,这种效果将发生在同一个 viewController 中。我更新了图像以反映我正在谈论的视图是主视图中的子视图。

【问题讨论】:

【参考方案1】:

我也遇到过类似的情况,点击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 个类,如果你觉得可以,请使用这段代码。希望它能在一定程度上解决你的问题。

【讨论】:

感谢您的回复。如果我理解正确,那么您所描述的基本上是两个视图控制器之间的翻转。类似于标准模态序列。查看我更新的图像。很抱歉造成混乱。【参考方案2】:

您可以使用两个UIViews,一个用于第一面,一个用于第二面。

显示第一个视图,隐藏第二个视图,并将第二个视图的框架设置为宽度为 0。

然后,当您的第一个视图可见时,将其框架设置为宽度等于 0。隐藏第一个视图,取消隐藏第二个视图,并将第二个视图的框架设置为所需的框架。

编辑:如果您的视图中有标签,这似乎效果不佳,因为这是一个 2D 翻转。对于那个很抱歉。 @Maverick 的回答在你的情况下可能会很有效。

【讨论】:

【参考方案3】:

在你的 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

【讨论】:

以上是关于如何翻转正面带有标签而背面带有另一个标签的视图 - 参见图片的主要内容,如果未能解决你的问题,请参考以下文章

如何隐藏带有另一个视图控制器的标签栏视图控制器?

Cordova如何翻转整个屏幕正面到背面的3D效果

从另一个视图类中隐藏带有标签的按钮不起作用。

在视图而不是模板中生成带有 Django 静态 url 的图像标签

如何创建一个像 Instagram 主页一样的页面视图控制器,它也可以滚动标签栏?

在RecyclerView中翻转CardView