2012-04-18 1 views
0

위로부터 슬라이딩 애니메이션을 사용하여 다른 뷰로 뷰를 대체하려고합니다. 나는 http://gentlebytes.com/2011/09/auto-layout-in-lion/에 게시 된 가이드를 따라 갔지만 NSConstraints는 없었다.animationDidStop : finished : not called

불행히도 내 애니메이션의 대리자 메서드 animationDidStop : finished :이 애니메이션의 끝에서 호출되지 않습니다.

- (void)slideViewControllerFromTop:(NSViewController *)controller { 
[self replacePlaceholderViewWith:controller block:^(NSView *placeholder, NSView *currentView, NSView *newView) { 
    NSRect initialFrameNewView = NSMakeRect(placeholder.bounds.origin.x, 2*placeholder.bounds.size.height - newView.frame.size.height - DISTANCE_FROM_TOP, placeholder.bounds.size.width, newView.frame.size.height); 
    [newView setFrame:initialFrameNewView]; 
    NSRect finalFrameNewView = NSMakeRect(placeholder.bounds.origin.x, placeholder.bounds.size.height - newView.frame.size.height - DISTANCE_FROM_TOP, 0.91*placeholder.bounds.size.width, newView.frame.size.height); 

    NSRect finalFrameCurrentView = NSMakeRect(currentView.frame.origin.x, currentView.frame.origin.y-placeholder.bounds.size.height, currentView.frame.size.width, currentView.frame.size.height); 

    CABasicAnimation *animation = [CABasicAnimation animation]; 
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    [animation setDelegate:self]; 
    [animation setDuration:0.5]; 
    animation.removedOnCompletion = YES; 

    [newView setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frame"]]; 
    [currentView setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frame"]]; 

    [placeholder addSubview:newView]; 
    [NSAnimationContext beginGrouping]; 
    [[newView animator] setFrame:finalFrameNewView]; 
    [[currentView animator] setFrame:finalFrameCurrentView]; 
    [NSAnimationContext endGrouping]; 
}]; 
} 

- (void)replacePlaceholderViewWith:(NSViewController *)controller block:(GBPlaceholderReplaceBlock)handler { 
    if (controller == self.currentViewController) return; 
    self.previousViewController = self.currentViewController; 
    self.currentViewController = controller; 
    NSView *placeholderView = self.contentView; 
    NSView *currentView = self.contentView.subviews.lastObject; 
    NSView *newView = self.currentViewController.view; 
    handler(placeholderView, currentView, newView); 
} 

- (void)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag { 
    if (!flag || self.contentView.subviews.count < 2) return; 
    [[self.contentView.subviews objectAtIndex:0] removeFromSuperview]; 
    self.previousViewController = nil; 
} 

답변

1

에 한번이 두

[newView setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frame"]]; 
[currentView setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"frame"]]; 

[newView.layer addAnimation:animation forKey:@"frame"]; 
[currentView.layer addAnimation:animation forKey:@"frame"]; 

를 대체하기 위해 그리고 당신의 클래스 파일의 상단에 #import <QuartzCore/QuartzCore.h>를 추가하는 것을 잊지 마세요 : 여기

내 코드입니다 .

+0

감사합니다. 그것은 트릭을했다. 처음에는 레이어가 필요하다고 생각했지만 어쨌든 애니메이션이 작동했기 때문에 실제로 필요하지 않다고 생각했습니다. – Jacopo

+0

@Jacopo 당신은 환영합니다 :) – Kjuly