2014-12-07 7 views
3

Mac OS X (NSView) 관련 질문입니다.Facebook Pop 애니메이션을 사용하여 NSView를 센터에서 어떻게 스케일합니까?

페이스 북의 POP 애니메이션을 사용하여 센터에서 NSView의 크기를 75 %까지 늘린 다음 다시 100 %로 변경하려고합니다.하지만 작동하지는 않습니다. kPOPLayerScaleXY가 작동하지 않는 것 감안할 때, 내가 한 다음하지만 왼쪽 상단에서 아래로 확장 할 것, 그리고 zoomIn가 false 인 경우, 너무 큰 간다이 (나에게 잘못된 결과를 제공합니다

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"]; 
+0

같은 문제는 계층과'anchorPoint'의 설정'frame' 후, 모두가 잘 작동합니다. – Sk0prion

답변

5

I을 . 대신 두 개의 애니메이션을 사용하여 마지막으로 작업 있어요 :

CGRect baseRect = CGRectMake(0, 0, 30, 24); 
    CGFloat scale = (zoomIn) ? 0.80 : 1.0; 

    CGFloat x = baseRect.origin.x; 
    CGFloat y = baseRect.origin.y; 

    if (zoomIn) { 
    x = floorf((baseRect.size.width * (1.0 - scale))/2); 
    y = floorf((baseRect.size.height * (1.0 - scale))/2); 
    } 

    [myView.layer pop_removeAllAnimations]; 

    POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; 
    animation.springBounciness = 8; 
    animation.toValue = [NSValue valueWithCGSize:CGSizeMake(scale, scale)]; 
    [myView.layer pop_addAnimation:animation forKey:@"zoom"]; 

    animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerTranslationXY]; 
    animation.springBounciness = 8; 
    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(x, y)]; 
    [myView.layer pop_addAnimation:animation forKey:@"translate"];