3
請注意,這是一個Mac OS X(NSView
)相關問題。我想使用Facebook的POP動畫從中心(到75%的大小),然後回到100%,但我不能讓它的工作。鑑於kPOPLayerScaleXY
似乎不工作,我做了以下內容,但是這給了我不正確的結果(因爲它似乎從左上角的縮小,而當zoomIn
是假的,它會太大:如何使用Facebook流行動畫從中心縮放NSView?
CGRect baseRect = CGRectMake(0, 0, 30, 24);
CGFloat scale = (zoomIn) ? 0.75 : 1.0;
CGFloat x = baseRect.origin.x;
CGFloat y = baseRect.origin.y;
CGFloat width = baseRect.size.width;
CGFloat height = baseRect.size.height;
if (zoomIn) {
width -= floorf((1.0 - scale) * width);
height -= floorf((1.0 - scale) * height);
x += floorf((width * (1.0f - scale))/2);
y += floorf((height * (1.0f - scale))/2);
}
CGRect scaleRect = CGRectMake(x, y, width, height);
[myView.layer pop_removeAllAnimations];
POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
animation.springBounciness = 8;
animation.toValue = [NSValue valueWithCGRect: scaleRect];
[myView.layer pop_addAnimation:animation forKey:@"zoom"];
同樣的問題。設置'frame'和'anchorPoint'後,所有工作都正常。 – Sk0prion 2016-11-01 16:35:44