gpt4 book ai didi

iOS - 翻转动画,从小到大

转载 作者:行者123 更新时间:2023-11-29 13:45:28 27 4
gpt4 key购买 nike

我正在尝试模拟在 iTunes iPad 应用程序中看到的翻转动画。在主要精选页面上,如果您点击新发行列表中的一张小海报,它将翻开以显示电影的所有详细信息。

点击海报时,我会这样做:

//...create newView

[self.view addSubview:poster]; //because the poster was previously in a scrollview

[UIView transitionWithView:self.view duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[poster removeFromSuperview];
[self.view addSubview:newView];
}
completion:NULL];

但是……整个 View 都翻转了,而不仅仅是海报。它垂直翻转而不是水平翻转,即使我指定了 FlipFromLeft。我做错了什么?

编辑:看来您必须使用某种容器 View 来执行此操作。所以我制作了一个,将海报添加到其中,然后创建了一个虚拟 UIView 用于测试:

CGPoint newPoint = [self.view convertPoint:CGPointMake(poster.frame.origin.x, poster.frame.origin.y) fromView:[poster superview]];
poster.frame = CGRectMake(0, 0, poster.frame.size.width, poster.frame.size.height);

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(newPoint.x, newPoint.y, poster.frame.size.width, poster.frame.size.height)];
[self.view addSubview:containerView];
[containerView addSubview:poster];


UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height)];
testView.backgroundColor = [UIColor redColor];

[UIView transitionWithView:containerView duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[poster removeFromSuperview];
[containerView addSubview:testView];
}
completion:NULL];

现在,红色的 UIView 出现在海报的位置,但是根本没有 Flipping 动画。为什么不呢?

最佳答案

您是在告诉 View 使用 self.view 进行转换,所以难怪整个 View 都具有动画效果。尝试使用海报 View 告诉过渡动画。

[UIView transitionWithView:poster.view duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[poster removeFromSuperview];
[self.view addSubview:newView];
}
completion:NULL];

关于iOS - 翻转动画,从小到大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7614583/

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