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