gpt4 book ai didi

iphone - 翻转 View iPhone

转载 作者:行者123 更新时间:2023-12-03 18:23:13 27 4
gpt4 key购买 nike

请考虑下面的代码,并告诉我我做错了什么。

我想在两个 UIView 之间切换。

不知何故,当我从初始 View 翻转时,我只是得到翻转的 View ,没有动画。当我向后翻转时,动画显示得很好。

翻转是由 View 本身上的按钮触发的。

- (IBAction)showMoreInfo:(id)sender
{
UIView *moreInfo = self.flipView;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

UIView *parent = self.view.superview;
[self.view removeFromSuperview];

[parent addSubview:moreInfo];

[UIView commitAnimations];

}



- (IBAction)showLessInfo:(id)sender
{
UIView *lessInfo = self.view;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.flipView cache:YES];

UIView *parent = self.flipView.superview;
[self.flipView removeFromSuperview];

[parent addSubview:lessInfo];

[UIView commitAnimations];

}

最佳答案

这可能是因为您没有使用容器 View 作为过渡 View 。请参阅 setAnimationTransition:forView:cache: 上的文档

If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:

  1. Begin an animation block.
  2. Set the transition on the container view.
  3. Remove the subview from the container view.
  4. Add the new subview to the container view.
  5. Commit the animation block.

尝试在 showMoreInfo: 的动画转换 View 中使用 self.view.superview

showLessInfo: 方法起作用的原因是您正在使用容器 View 。

关于iphone - 翻转 View iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/843534/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com