【问题标题】:Flip and size expand button animation翻转和大小展开按钮动画
【发布时间】:2011-10-31 11:46:48
【问题描述】:

我想使用动画翻转和展开按钮

代码:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mybutton cache:YES];
[mybutton setFrame:CGRectMake(mybutton.frame.origin.x, mybutton.frame.origin.x, 200, 200)];
[UIView commitAnimations];

这个动画有问题:
- 按钮正在翻转,但在进行半圆形翻转后它正在扩展。
- 按钮翻转后位置不准确。

我该如何解决?

【问题讨论】:

    标签: iphone objective-c animation flip


    【解决方案1】:

    尝试完全注释掉 setFrame,它应该会更好地翻转。还可以尝试将缓存设置为 NO。根据文档,您不应该修改在动画本身期间正在转换的视图 - cache:NO 会有所帮助,但它仍然不正确。

    您通常会为 setAnimationTransition 函数提供一个父视图,然后在您获取旧子视图并将其从子视图中删除之后,然后添加新子视图。这会产生一个子视图被翻转到后面而新的子视图被翻转为焦点的错觉。转换发生在父级上,尽管其中包含子级。

    无论哪种方式,请尝试将 setFrame 注释一分钟,它应该看起来更一致。

    【讨论】:

      【解决方案2】:

      由于它们都是单独的动画,您也可以尝试使用 AnimationDidStopSelector,一旦动画完成就会被调用;)

      哦,顺便说一句,在您的 CGRectMake 中,您再次使用 x 坐标作为 y 坐标,这可能是位置不准确的原因 ^^

      类似这样的:

      - (void)yourFunction {
          [UIView beginAnimations:nil context:indexPath];
          [UIView setAnimationDuration:0.3];
          [UIView setAnimationDelegate:self];
          [UIView setAnimationDidStopSelector:@selector(functionEnded:finished:context:)];
          [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mybutton cache:YES];
          [UIView commitAnimations];
      }
      
      - (void)functionEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
              [UIView beginAnimations:nil context:indexPath];
              [UIView setAnimationDuration:1.3];
              [mybutton setFrame:CGRectMake(mybutton.frame.origin.x, mybutton.frame.origin.y, 200, 200)];
              [UIView commitAnimations];
      }
      

      【讨论】:

      • 我需要同时翻转和展开按钮。示例:在 iPad 上打开 iTunes,然后单击一首歌曲。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多