[layerpresentationLayer];
#import <QuartzCore/QuartzCore.h>
– (void)viewDidLoad
{
[superviewDidLoad];
// アニメーションさせるマーク 10×10で青
UIView *mark = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
mark.backgroundColor = [UIColorblueColor];
[self.view addSubview:mark];
// 左上から真ん中に3秒かけて移動
[UIViewanimateWithDuration:3animations:^{
mark.center = self.view.center;
}];
}
3. touchesBegan にて座標をログ出力する
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// アニメーション中の座標を取得
// 1. UIView property から
UIView *mark = [self.view.subviews objectAtIndex:0];
NSLog(@”¥n¥n UIView ———- x:%f, y:%f”, mark.center.x, mark.center.y);
// 2. CALayer property から
NSLog(@”¥n CALayer ——— x:%f, y:%f”, mark.layer.position.x, mark.layer.position.y);
// 3. presentationLayer から
CALayer *mLayer = [mark.layer presentationLayer];
NSLog(@”¥n presentationLayer x:%f, y:%f”, mLayer.position.x, mLayer.position.y);
}
「結果」
こんなかんじで、presentationLayer を使えば、動いているViewの座標が取得できました。
UIView ———- x:160.000000, y:250.000000
CALayer ——— x:160.000000, y:250.000000
presentationLayer x:31.265623, y:46.516628
UIView ———- x:160.000000, y:250.000000
CALayer ——— x:160.000000, y:250.000000
presentationLayer x:61.037354, y:93.575172
UIView ———- x:160.000000, y:250.000000
CALayer ——— x:160.000000, y:250.000000
presentationLayer x:100.058083, y:155.253098
UIView ———- x:160.000000, y:250.000000
CALayer ——— x:160.000000, y:250.000000
presentationLayer x:159.100174, y:248.577682