【问题标题】:Darkening UIView while flipping over using UIViewAnimationTransitionFlipFromRight使用 UIViewAnimationTransitionFlipFromRight 翻转时使 UIView 变暗
【发布时间】:2010-04-15 11:28:41
【问题描述】:

我正在使用标准动画块从一个视图翻转到另一个视图,如下所示:

[UIView beginAnimations:@"FlipAnimation" context:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView setAnimationBeginsFromCurrentState:NO];
[containerView exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[UIView commitAnimations];

在动画过程中,“从”视图开始翻转时变暗。由于我在两边都使用了几乎相同的视图,而没有覆盖整个视图(它的意思是表示正在翻转的物理卡),这看起来非常可怕。使用[UIColor clearColor] 作为每个关联UIViewbackgroundColor 属性并没有帮助,因为透明区域似乎也变暗了。

关于如何摆脱这种变暗效果的任何想法?

【问题讨论】:

    标签: iphone objective-c core-animation


    【解决方案1】:

    似乎您必须使用核心动画转换“手动”制作动画。 我将动画分为两部分。首先,我用动画将“viewOne”旋转到一半,在没有动画的情况下将“viewTwo”旋转到另一个方向的一半。 动画的前半部分完成后,我在委托方法中完成其余部分。 您的参数可能会有所不同:)

    倾斜是由我找到的其他一些 StackOverflow 答案提供的。

    - (IBAction)flip:(id)sender
    {
      UIView* viewOne = [self.view.subviews objectAtIndex:0];
      UIView* viewTwo = [self.view.subviews objectAtIndex:1];
    
      viewOne.hidden = YES;
    
      CATransform3D matrix = CATransform3DMakeRotation (M_PI / 2, 0.0, 1.0, 0.0);
      CATransform3D matrix2 = CATransform3DMakeRotation (-M_PI / 2 , 0.0, 1.0, 0.0);
      matrix = CATransform3DScale (matrix, 1.0, 0.975, 1.0);
      matrix.m34 = 1.0 / -500;
    
      matrix2 = CATransform3DScale (matrix2, 1.0, 0.975, 1.0);
      matrix2.m34 = 1.0 / -500;
    
      viewOne.layer.transform = matrix2;
    
      [UIView beginAnimations:@"FlipAnimation1" context:self];
      [UIView setAnimationDuration:1];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(animationPartOneDone)];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    
      viewTwo.layer.transform = matrix;
    
      [UIView commitAnimations];    
    }
    
    -(void)animationPartOneDone
    {   
      UIView* viewOne = [self.view.subviews objectAtIndex:0];
      UIView* viewTwo = [self.view.subviews objectAtIndex:1];
    
    
      viewOne.hidden = NO;
      viewTwo.hidden = YES;
    
      CATransform3D matrix = CATransform3DMakeRotation (2 * M_PI, 0.0, 1.0, 0.0);
    
      matrix = CATransform3DScale (matrix, 1.0, 1.0, 1.0);
    
      [UIView beginAnimations:@"FlipAnimation2" context:self];
      [UIView setAnimationDuration:1];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
      viewOne.layer.transform = matrix;
    
      [UIView commitAnimations];    
    
      [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多