1

UIView画面全体にまたがる名前付きの containerView を作成しました。このビューCATransormLayerでは、次の寸法を持つ UIView を追加する必要があります。

CATransformlayer : doubleSidedLayer  
Height = containerView.frame.size.height  
Width = containerView.frame.size.width  

UIView : stripView
Height = containerView.frame.size.height  
Width = 20;

両方の x 位置は、変数 positionX によって指定されます。DoubleSidedLayer理論的には、との両方stripViewがオーバーラップする必要があります。しかし、そうではありません。

これがコードです。

CGRect containerFrame =CGRectMake(0,0,self.view.frame.size.height,self.view.frame.size.width);
NSLog(@"container frame = %f %f %f %f",containerFrame.origin.x,containerFrame.origin.y,containerFrame.size.width,containerFrame.size.height);
UIView *containerView = [[UIView alloc]initWithFrame:containerFrame];
[containerView setBackgroundColor:[UIColor grayColor]];

float positionX = containerFrame.size.width/4;//This is the position where the stripView and doubleSidedLayer must be placed

//Configuration of CATransformLayer.
CGRect doubleLayerFrame = CGRectMake(positionX,0,containerFrame.size.width/2,containerFrame.size.height);
CATransformLayer *doubleSidedLayer  = [CATransformLayer layer];
[doubleSidedLayer setFrame:doubleLayerFrame];

NSLog(@"DoubleSidedLayer frame = %f %f %f %f",doubleSidedLayer.frame.origin.x,doubleSidedLayer.frame.origin.y,doubleSidedLayer.frame.size.width,doubleSidedLayer.frame.size.height);
NSLog(@"DoubleSidedLayer bounds = %f %f %f %f",doubleSidedLayer.bounds.origin.x,doubleSidedLayer.bounds.origin.y,doubleSidedLayer.bounds.size.width,doubleSidedLayer.bounds.size.height);
NSLog(@"Anchor Points = %f %f",doubleSidedLayer.anchorPoint.x, doubleSidedLayer.anchorPoint.y);
NSLog(@"position = %f %f",doubleSidedLayer.position.x,doubleSidedLayer.position.y);

//Configuring top layer
CALayer *topLayer = [[CALayer alloc]init];
[topLayer setFrame:doubleLayerFrame];
[topLayer setContents:(id)[UIImage imageNamed:@"1.png"].CGImage];
[topLayer setZPosition:2];
[topLayer setDoubleSided:NO];

//Adding the layers
[doubleSidedLayer addSublayer:topLayer];
[containerView.layer addSublayer:doubleSidedLayer];

//Adding the stripView
UIView *stripView = [[UIView alloc]initWithFrame:CGRectMake(positionX, 0, 20,containerView.frame.size.height)];
[stripView setBackgroundColor:[UIColor cyanColor]];
[containerView addSubview:stripView];
NSLog(@"Strip frame = %f %f %f %f",stripView.frame.origin.x,stripView.frame.origin.y,stripView.frame.size.width,stripView.frame.size.height);

//Adding the containerView to the main view
[self.view addSubview:containerView];

ログ ステートメントから、doubleSidedLayer と stripView のフレームを確認できます。

doubleSidedLayer frame = 120.000000 0.000000 240.000000 300.000000   
strip frame = 120.000000 0.000000 20.000000 300.000000

しかし、両者は重なりません。これがスクリーンショットです。ここに画像の説明を入力

注:横向きで作業しています。

4

2 に答える 2

0

私は自分の間違いを理解することができました。topLayerの構成に問題がありました。これは、の範囲内に収まる必要がありますdoubleSidedLayer。だから私はに変更[topLayer setFrame:doubleLayerFrame]しました[topLayer setFrame:doubleSidedLayer.bounds]。これで私の問題は修正されました。

于 2013-03-11T06:54:07.010 に答える
0

あなたが探しているものを達成するためのより簡単な方法があるのだろうか. たとえば、ある画像から別の画像に「反転」したいビューがある場合、次のようなものを使用します。

[UIView transitionWithView:self.imageView
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionCurveEaseInOut
                animations:^{
                    if (self.flipped)
                        self.imageView.image = [UIImage imageNamed:@"front.png"];
                    else
                        self.imageView.image = [UIImage imageNamed:@"back.png"];

                    self.flipped = !self.flipped;

                }
                completion:nil];

私はイメージビューでこれを行っていますが、どのUIViewコントロールを使用してもコンセプトは同じように機能します。いくつかのコンテナー ビューがあり、このanimationsブロックでコントロールを追加/削除または表示/非表示にする場合は、それも実行できます。の最初のパラメーターにコンテナー ビューを使用するだけtransitionWithViewです。

于 2013-03-06T14:53:01.830 に答える