4

画像に「ブラインドダウン」効果を作成して、画像が「ブラインドダウン」して表示されるようにしたい。

このJavaScriptトランジションのようなもの: https ://github.com/madrobby/scriptaculous-http : //madrobby.github.io/scriptaculous/effect-blinddown/

マスクの位置を手動で変更すると、マスクの背後にある画像が非表示および表示されるため、マスクは正しく設定されていますが、アニメーション化されません。それは最終的にアニメートの最終位置になり、実際にブラインドになることはありません。

助けてください!たぶん、これはブラインドダウン効果を達成するための最良の方法ではありませんか?

// create a new layer
CALayer *numberLayer = [[CALayer alloc] init];

// render the number "7" on the layer
UIImage *image = [UIImage imageNamed:@"number-7.png"];
numberLayer.contents = (id) [image CGImage];
numberLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); // width and height are 50
numberLayer.position = position;

// create a new mask that is 50x50 the size of the image
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();

CGPathAddRect(path, nil, CGRectMake(0, 0, 50, 50));

[maskLayer setPath:path];
[maskLayer setFillColor:[[UIColor whiteColor] CGColor]];

[theLayer setMask:maskLayer];

[maskLayer setPosition:CGPointMake(0, 0)]; // place the mask over the image

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[maskLayer setPosition:CGPointMake(0, 50)]; // slide mask off the image
// this should shift the blind away in an animation
// but it doesn't animate
[UIView commitAnimations]; 
[maskLayer release];

[boardLayer addSublayer:numberLayer];
[numberLayer release];
4

1 に答える 1

0

試してみる別のこと。CALayerさんのプロパティをチェックアウトしcontentRectます。レイヤー上の「ビューポート」として機能します。アニメートするcontentRectには、縮小値から始めて、フル サイズに設定します。Core Animation がアニメーション化を行います。

それがまさにあなたが探している効果かどうかはわかりませんが、覚えておくべきことがいくつかあります。

  • contentsRect値が 0.0 から 1.0 の間の浮動小数点であることを意味する「単位座標」にあります (0.0 は何も表示しないことを意味し、1.0 はすべてを表示することを意味します)。

  • レイヤー座標は UIView 座標から反転されます。したがって、0.0、0.0 は左下で、値は右に上がります。適切な効果を得るには、いくつかの調整を行う必要があります。

  • ブラインドの内容によっては、 を設定する必要がある場合がありますmasksToBounds=YES

于 2010-05-08T16:16:56.117 に答える