2012-05-11 5 views
0

현재 요소 크기를 조정하거나 이동하기 위해 일부 핵심 애니메이션을 구현하는 프로젝트에서 작업 중입니다. 우리는 많은 Mac에서 이러한 애니메이션이 상당히 간단하지만 프레임 속도가 크게 떨어지는 것을 보았습니다.코어 애니메이션 : 프레임 속도

// Set some additional attributes for the animation. 
    [theAnim setDuration:0.25]; // Time 
    [theAnim setFrameRate:0.0]; 
    [theAnim setAnimationCurve:NSAnimationEaseInOut]; 

    // Run the animation. 
    [theAnim startAnimation]; 
    [self performSelector:@selector(endAnimation) withObject:self afterDelay:0.25]; 

명시 적 프레임 속도를 주장 하는가 (예를 들어 60.0 대신 0.0을 떠나는) 등 스레드에 더 우선 순위를 넣어, 그에 가능성이 프레임 속도를 올리는 예를 들면 다음과 같습니다입니까? 이것들을 모두 움직이는 더 좋은 방법이 있습니까?

답변

6

The documentation for NSAnimation

0.0의 프레임 레이트를 빨리 ... 프레임 속도가 빠른 속도 정상적으로

보장되지 가능한 이동 수단을 말한다 합리적 상기 될 60 fps와 동일합니다. 코어 애니메이션 대신 NSAnimation의

NSAnimation를 사용


정말 코어 애니메이션 (AppKit의 자사 두드려)의 일부가 아닙니다. 대신 Core Animation을 사용하여 애니메이션을 제작하는 것이 좋습니다. 같은 애니메이션 뭔가 코어 애니메이션에 당신이
  • 스위치 애니메이션 된 뷰 YES로 - (void)setWantsLayer:(BOOL)flag 설정 파일에
  • 가져 오기 프로젝트
  • 에 QuartzCore.framework 추가

    1. 위의 애니메이션 지속 시간에서 "암시 적 애니메이션"(레이어 속성 만 변경)이 가장 적합 할 수 있습니다.

      CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"frame"]; 
      [moveAnimation setDuration:0.25]; 
      // There is no frame rate in Core Animation 
      [moveAnimation setTimingFunction:[CAMediaTimingFunction funtionWithName: kCAMediaTimingFunctionEaseInEaseOut]]; 
      [moveAnimation setFromValue:[NSValue valueWithCGRect:yourOldFrame]] 
      [moveAnimation setToValue:[NSValue valueWithCGRect:yourNewFrame]]; 
      
      // To do stuff when the animation finishes, become the delegate (there is no protocol) 
      [moveAnimation setDelegate:self]; 
      
      // Core Animation only animates (not changes the value so it needs to be set as well) 
      [theViewYouAreAnimating setFrame:yourNewFrame]; 
      
      // Add the animation to the layer that you 
      [[theViewYouAreAnimating layer] addAnimation:moveAnimation forKey:@"myMoveAnimation"]; 
      

      그런 다음 콜백에서 당신이

      - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)isFinished { 
          // Check the animation and perform whatever you want here 
          // if isFinished then the animation completed, otherwise it 
          // was cancelled. 
      } 
      
  • +0

    이 굉장 구현 !! : 그러나 당신이 더 많은 제어를 원하는 경우에 당신은 명시 적으로 애니메이션이 같은 것을 사용할 수 있습니다 위대한 팁 데이비드 감사 -이 구현 후 성능 NSAnimation 비교할 수 없습니다. 훨씬 빠르다. – Zakman411

    관련 문제