我有2个观点。我想要一张卡片沿其轴翻转和旋转以显示另一个视图。
因此,当我点击view1时,view1应该翻转但是在它围绕y轴旋转的意义上翻转以显示视图2.
我在IOS中使用FLIP指令,但这不是我正在寻找的“旋转”:
[UIView transitionFromView:(self.displayingPrimary ? self.primaryView : self.secondaryView)
toView:(self.displayingPrimary ? self.secondaryView : self.primaryView)
duration: 2.0
options: (self.displayingPrimary ? UIViewAnimationOptionTransitionFlipFromLeft :
UIViewAnimationOptionTransitionFlipFromRight) | UIViewAnimationOptionShowHideTransitionViews
completion:^(BOOL finished) {
if (finished) {
self.displayingPrimary = !self.displayingPrimary;
}
}];
答案 0 :(得分:2)
如果您不喜欢内置的翻转转换,有几种方法可以使用Quartz在iOS上将一个视图翻转到另一个视图。以下两个代码片段都要求您#import <QuartzCore/QuartzCore.h>
并且还要链接到QuartzCore框架。请注意,我编写的这两个函数都假设两个视图都被添加为具有相同框架的子视图,其中一个被隐藏(setHidden:
)。
第一个函数将使用2D变换将一个视图翻转到另一个视图。这样更有效,它真正做的就是沿x轴缩放。在高速下,它看起来很不错,IMO。
+ (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];
}