【问题标题】:how to make flip animation in ios within views如何在视图中的ios中制作翻转动画
【发布时间】:2013-06-04 15:03:14
【问题描述】:

我在主视图中添加了 4 个 UIView 类型的子视图。我想用平滑的翻转动画翻转这些视图。我已经尝试过但无法成功完成它。这是我使用的代码。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:signUpView cache:YES];
[UIView commitAnimations];

它翻转一半并立即显示另一个视图。 告诉我怎么做?

【问题讨论】:

标签: ios uiviewanimation flip


【解决方案1】:

在开始时我将我的 firstView 添加到 containerView

[self.containerView addSubview:firstView];

在那之后你需要添加你的翻转过渡

[UIView transitionWithView:self.containerView
                  duration:1
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{ [firstView removeFromSuperview]; [self.containerView addSubview:secondView]; }
                completion:NULL];

【讨论】:

    【解决方案2】:

    你甚至可以试试这个

    CATransition *animation = [CATransition animation];
        animation.delegate = self;
        animation.duration = 1;
        animation.timingFunction = UIViewAnimationCurveEaseInOut;
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 1;
        animation.removedOnCompletion = NO;
        animation.type = @"oglFlip";
    
        [yourView.layer addAnimation:animation forKey:@"animation"];
    

    如果您愿意,可以添加更多动画类型:

    animation.type = @"cube";
    animation.type = @"suckEffect";
    animation.type = @"suckEffect";
    animation.type = @"pageCurl";
    animation.type = @"pageUnCurl";
    animation.type = @"cameraIrisHollowOpen ";
    animation.type = @"cameraIrisHollowClose ";
    

    【讨论】:

      【解决方案3】:

      尝试分别翻转每个视图。可能是这样的

      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDuration:0.5];
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:signInView cache:YES];
      [UIView commitAnimations];
      //
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDuration:0.5];
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:signUpView cache:YES];
      [signInView setHidden:YES];//or you can use remove subview
      [signUpView setHidden:NO];// you can use addsubview
      [UIView commitAnimations];
      

      【讨论】:

      • UIView 动画的beginAnimations: commitAnimations: 方法自iOS4 起已弃用,建议改用基于块的动画方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      相关资源
      最近更新 更多