組み込みのフリップ変換が気に入らない場合は、iOSでQuartzを使用して1つのビューを別のビューにフリップする方法がいくつかあります。#import <QuartzCore/QuartzCore.h>
次の2つのコードスニペットは、QuartzCoreフレームワークへのリンクとQuartzCoreフレームワークへのリンクの両方を必要とします。私が書いた両方の関数は、両方のビューが同じフレームのサブビューとして追加され、そのうちの1つが非表示になっていることを前提としていることに注意してください(setHidden:
)。
最初の関数は、2D変換を使用して1つのビューを別のビューに反転します。これはより効率的であり、実際に行うのは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];
}
2番目の関数は、実際の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];
}