以前のいくつかの StackOverFlow の質問と github CA360のこの例から、「前面」に画像、背面にテキストを使用してフリップ カードをシミュレートすることができました。ただし、カードの裏のテキストは上下逆になっていて、水平に中央に配置しただけです。テキストを適切に配置し、カードの垂直方向の中央に配置するにはどうすればよいですか?
カード表面:

カードの裏 (テキストを垂直方向に配置して中央揃えにする方法は?):

[アップデート]
最上層の不透明度を 0.5 に設定してから、実際の反転が発生したときに通常の状態にリセットされるように、背面レイヤーを「プリフリップ」するというアイデアを得ました。

私の「プレフリップ」は次のようになります。
cardBack.transform = CATransform3DMakeRotation(M_PI, 1.0f, 0.0f, 0.0f); // Pre-flip card
今、私は垂直設定への組み込みの方法を見つけるか、それを難しい方法で行う必要があります.半分の距離...フォントの高さ...さらに...
2 層のカード コンテナーを設定する (参照):
- (無効)loadView {
UIView *myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] 境界]];
myView.backgroundColor = [UIColor whiteColor];
self.view = myView;
cardContainer = [CATransformLayer レイヤー];
cardContainer.frame = CGRectMake(300, 250, 200, 150);
CALayer *cardFront = [CALayer レイヤー];
cardFront.frame = cardContainer.bounds;
cardFront.zPosition = 5; // カード裏面の zPosition より高い
cardFront.contents = (id)[UIImage imageNamed:@"Ben"].CGImage;
cardFront.opacity = 0.5;
[cardContainer addSublayer:cardFront];
/*
https://stackoverflow.com/questions/2209734/add-text-to-calayer
*/
CATextLayer *cardBack = [CATextLayer レイヤー];
cardBack.string = @"こんにちは";
cardBack.frame = cardContainer.bounds;
cardBack.zPosition = 4;
cardBack.backgroundColor = [[UIColor grayColor] CGColor];
cardBack.alignmentMode = kCAAlignmentCenter;
CFTypeRef *font = (CFTypeRef *)CTFontCreateWithName(CFSTR("Times"), 48, NULL);
cardBack.font = フォント;
[cardContainer addSublayer: cardBack];
[self.view.layer addSublayer:cardContainer];
}
別の SOF 質問から借用してカードをめくるコード:
- (無効) フリップカード {
// [self.flipTimer 無効];
// if (反転){
// 戻る;
// }
NSLog(@"Count=%d", カウント);
id animationsBlock = ^{
// self.backView.alpha = 1.0f;
// self.frontView.alpha = 0.0f;
// [self BringSubviewToFront:self.frontView];
// 反転 = YES;
NSLog(@"フリッピング...");
CALayer *layer = cardContainer;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
回転と視点変換.m34 = 1.0 / 500;
もし (カウント == 0) {
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI, 1.0f, 0.0f, 0.0f);
} else { // 画像に戻す
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 0.0f, 0.0f, 1.0f, 1.0f);
}
layer.transform = rotationAndPerspectiveTransform;
};
カウント = (カウント + 1) % 2;
[UIView animateWithDuration:1.25
遅延:0.0
オプション: UIViewAnimationCurveEaseInOut
アニメーション:アニメーション ブロック
完了:なし];
}