2012-01-16 3 views
0

나는 애니메이션을 적용하는 많은 CAShapeLayers가있는 하위 뷰가 있으며 이로 인해 애니메이션이 느려집니다. 그 외에도 애니메이션은 순차적으로 실행되어야하지만, 왜 그런지는 거의 모릅니다. 동시에 거의 동시에 실행됩니다. 이 문제를 해결하기 위해 내가 바꿀 수있는 것이 있습니까? (나는 animateWithDuration을 사용하고있다.)iOS - 애니메이션을 느리게 만드는 다중 레이어

니펫 :

for (id layer in self.layer.sublayers) { 
... 
    [UIView animateWithDuration:1.5f 
         delay:0.0f 
         options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
           subLayer.affineTransform = CGAffineTransformScale(subLayer.affineTransform, 1.5, 1.5); 
           [subLayer setZPosition:1000];  
           } 
        completion:^(BOOL finished) { 
         [UIView animateWithDuration:1.0f 
               delay:1.5f 
              options: UIViewAnimationOptionAllowUserInteraction 
             animations:^{ subLayer.affineTransform = CGAffineTransformIdentity; 
             } 
             completion:nil 
             ]; 

           }]; 
... 
} 

나는 애니메이션 방식을 변경했습니다,하지만 여전히, 그것은 부드러운되지 않습니다 :

NSOperationQueue *queue = [NSOperationQueue new]; 

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self 
                     selector:@selector(newCicle) 
                      object:nil]; 
[queue addOperation:operation]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3f]; 
[UIView setAnimationCurve: UIViewAnimationCurveLinear]; 

int layerNumber = 1; 
for (id layer in self.layer.sublayers) { 
    if ([layer isKindOfClass:[CAShapeLayer class]]) { 
     int k = layerNumber % SQHOR; 
     int i = ceil((float)layerNumber/(float)SQHOR); 
     CGColorRef color = nil; 

     if (changed[i][k]) { 
      if (matrix[i][k]) { 
       color = [[UIColor redColor] CGColor]; 
      } 
      else { 
       color = [[UIColor whiteColor] CGColor]; 
      } 

      CAShapeLayer *subLayer = (CAShapeLayer*)layer;            

      subLayer.fillColor = color; 

     } 
     layerNumber++; 
    } 

} 

[UIView commitAnimations];  
+0

당신이 몇 가지 코드 조각을 붙여 넣을 수 있습니까? :) – Kjuly

+0

위에 게시 : D –

답변

0

은 레이어 또는 당신의 superlayer에 setShouldRasterize:YES을 설정하십시오.

+0

이것은 애니메이션 품질을 저하 시켰지만 빠르지 않았습니다. –

+0

내가 애니메이트하는 방식을 업데이트했지만 스레드를 사용하여 사전 처리를 수행하더라도 애니메이션은 여전히 ​​부드럽지 않습니다. –

1

애니메이션이 당신의 모든 애니메이션 지연 시간을 계산, 순차적으로 실행해야하는 경우는 다음과 같이해야합니다 것 :

CGFloat everySubLayerAnimationDuration = 1.5f; // or other 
for (int i = 0; i < sublayers.count; i++) 
{ 
    [UIView animateWithDuration: everySubLayerAnimationDuration * i 
        delay:0.0f 
    ...... 
} 
+0

실제로 애니메이션은 한 번에 모두 발생해야하지만 전처리 시간 외에도 1500 개의 애니메이션 레이어가 있습니다. 어떻게해야합니까? –

+0

1500 개의 레이어 애니메이션이 절대로 부드럽 지 않습니다. iPhone/iPad CPU/GPU는 해당 레이어에 애니메이션을 적용 할 수 없습니다. 레이어를 줄이기 위해 앱을 다시 디자인하십시오. – fishinear

관련 문제