有几个方法可以使一个视图翻转到另一个使用iOS上的石英,如果你不喜欢内置的翻转转型。以下两个代码片段都要求您输入#import <QuartzCore/QuartzCore.h>
,并且还链接到QuartzCore框架。请注意,我写的两个函数都假设这两个视图都被添加为具有相同框架的子视图,并且其中一个被隐藏(setHidden:
)。
第一个功能将使用2D转换将一个视图翻转到另一个视图。这是更有效的,它所做的只是沿x轴缩放。在高速下,它看起来不错,国际海事组织。
+ (void)flipFromView1:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration completion:(void (^)(BOOL finished))completion
{
duration = duration/2;
[v2.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[v1.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
} completion:^(BOOL finished){
[v1 setHidden:YES];
[v2 setHidden:NO];
}];
[UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
[v2.layer setAffineTransform:CGAffineTransformMakeScale(1, 1)];
} completion:completion];
}
第二个函数执行实际的3D转换。请注意,如果使用此3D转换旋转的视图在3D空间中的其他子视图之上或之下,那么您可以在此动画期间看到其他视图隐藏或隐藏。
+ (void)flipFromView2:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration rToL:(BOOL)rToL completion:(void (^)(BOOL finished))completion
{
duration = duration/2;
v2.layer.transform = CATransform3DMakeRotation((rToL ? -1.57079633 : 1.57079633), 0, 1, 0);
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
v1.layer.transform = CATransform3DMakeRotation((rToL ? 1.57079633 : -1.57079633), 0, 1, 0);
} completion:^(BOOL finished){
[v1 setHidden:YES];
[v2 setHidden:NO];
}];
[UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
v2.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0);
} completion:completion];
}
怎么样已经内置UIModalTransitionStyleFlipHorizontal – Josiah
那你最终会做这个?我很好奇什么最终为你工作最好(不管它是否是这个线程的一部分)。 – Mathew