我正在尝试模拟在 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];
但是......整个视图翻转,而不仅仅是海报。它垂直翻转而不是水平翻转,即使我指定了 FlipFromLeft。我究竟做错了什么?
编辑:您似乎必须使用某种容器视图来执行此操作。所以我做了一个,添加了海报,然后创建了一个虚拟 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 动画。为什么不?