【问题标题】:Flip Right UIView1 to UIView2向右翻转 UIView 到 UIView 2
【发布时间】:2012-09-09 11:04:16
【问题描述】:

我在同一个UIViewController 中有两个UIViews VW1 和VW2。 我正在尝试从 VW1 向右翻转到 VW2 并使用以下我不知道如何以及在何处调用该方法的代码?

-(void)FlipFromRight
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2  cache:YES];

    [UIView commitAnimations];
}

上面的代码不适合我。

【问题讨论】:

  • 我想在屏幕上从右向左滑动时在视图之间进行翻转。我还尝试在视图之间使用滑动手势,但它不起作用,它只适用于不同的 ViewControllers跨度>
  • 尝试在上述方法中隐藏和只显示一个视图。在方法上定义条件,如果隐藏则显示 view1,否则显示 view2 ...

标签: iphone uiview uiviewcontroller flip


【解决方案1】:

你需要做的:

if ([VW1 superview])
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];  
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aTableBGView cache:NO];

        [VW1 removeFromSuperview];
        [mainView addSubview:VW2];
        [mainView sendSubviewToBack:VW1];
    }
    else
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];  
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aTableBGView cache:NO];

        [[mainView viewWithTag:2001] removeFromSuperview]; // VW2's tag ID
            [mainView addSubview: VW1];
        [mainView sendSubviewToBack: VW2];
    }   
    [UIView commitAnimations];

【讨论】:

    【解决方案2】:

    这里在导航栏或 MainViewcontroller 上添加一个类似名称“btnSwipe”的 uIButton,然后只需给出按钮标题,例如“Left”。 之后用下面的方法给出动作事件

    -(IBAction)FlipFromRight:(id)sender
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        if ([btnSwipe.titleLabel.text isEqualToString:@"Left"])
       {
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:uiView1  cache:YES];
    [btnDraw setTitle:@"Right" forState:UIControlStateNormal];
       }
    else{
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2  cache:YES];
    [btnDraw setTitle:@"Left" forState:UIControlStateNormal];
    }
    
        [UIView commitAnimations];
    }
    

    这里只需将 ib 中的 IBAction 提供给 btnSwipe,它就会起作用

    我希望这对你有用..

    :)

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多