OK、ここでは、グレー表示でマスクを使用する別の方法があります。私は実際に、blueViewとgreyViewを使ってこれをテストしました。ここでは、灰色が青色に覆い隠されています。灰色のレイヤーが表示されるように、灰色のレイヤーにマスクレイヤーを配置します。マスクを灰色のレイヤーから動かすと、灰色のレイヤーが動かずに消えるようになり、青色は灰色が消える場所を通ります。
これを試したい場合は、単一のビューでXCodeで空のプロジェクトを作成し、このコードをviewDidLoadの中に配置します。それが私がこれをテストした方法です。
self.view.backgroundColor = [UIColor whiteColor];
UIView* blueView = [[[UIView alloc] init] autorelease];
blueView.backgroundColor = [UIColor blueColor];
blueView.frame = CGRectMake(50,50,100,100);
UIView* grayView = [[[UIView alloc] init] autorelease];
grayView.backgroundColor = [UIColor grayColor];
grayView.frame = CGRectMake(50,50,100,100);
[self.view addSubview:blueView];
[self.view addSubview:grayView]; // gray covers the blue
// Create a mask to allow the grey view to be visible and cover up the blue view
CALayer* mask = [CALayer layer];
mask.contentsScale = grayView.layer.contentsScale; // handle retina scaling
mask.frame = grayView.layer.bounds;
mask.backgroundColor = [UIColor blackColor].CGColor;
grayView.layer.mask = mask;
// Animate the position of the mask off the grey view, as the grey becomes unmasked,
// that part of the grey "dissappears" and is no longer covering the blue underneath
CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"position"];
a.duration = 4;
a.fromValue = [NSValue valueWithCGPoint:mask.position];
CGPoint newPosition = mask.position;
newPosition.y += mask.bounds.size.height;
a.toValue = [NSValue valueWithCGPoint:newPosition];
a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[mask addAnimation:a forKey:@"colorize"]; // animate presentation
mask.position = newPosition; // update actual position
は#importsでトップでこの行を忘れないでください:
#import <QuartzCore/QuartzCore.h>
私は好奇心が強いです。 UIViewContentModeTopと100%から0%に見える "最初の"画像の高さをアニメーション化しても機能しませんでしたか? –
@ZakyGerman、Nope、それは反対方向にそれを明らかにする、上からの尺度です。私たちはアニメーションのための簡単なスプライトシートを使いました。 –
@ShaiMishaliジェスチャーでこれを持っていますか? –