0
我正在使用CABasicAnimation
來更改邊界屬性,然後使用它來更改圖層的位置屬性。是否可能同時做到這兩點?有點像改變UIView
的框架?同時縮放和移動圖層
CGRect oldBounds = mask.bounds;
CGRect newBounds = CGRectMake(0,0, rect.size.width * scale, rect.size.height * scale);
NSLog(@"%@", NSStringFromCGRect(newBounds));
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];
animation.fromValue = [NSValue valueWithCGRect:oldBounds];
animation.toValue = [NSValue valueWithCGRect:newBounds];
mask.bounds = newBounds;
[mask addAnimation:animation forKey:@"bounds"];
CGPoint oldPos = mask.position;
CGPoint newPos = CGPointMake(rect.origin.x * scale, rect.origin.y * scale);
CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"position"];
animation2.fromValue = [NSValue valueWithCGPoint:oldPos];
animation2.toValue = [NSValue valueWithCGPoint:newPos];
mask.position = newPos;
[mask addAnimation:animation2 forKey:@"position"];
請檢查我的代碼。你的意思是嗎?用這種方式,它看起來像是先縮放然後移動。 – 0xSina 2012-08-10 00:25:23
好像你回答了你自己的問題? – nielsbot 2012-08-10 00:26:32
如果您將「layer.bounds」和「layer.position」的分配移除,會發生什麼情況?另外,使用'addAnimation:forKey:','key'參數可供您自己參考 - 圖層不關心它。 – nielsbot 2012-08-10 00:30:04