2013-08-02 5 views
0

내 프로젝트 사용 UICollectionViewUICollectionViewCell을 터치하여 확장/축소 할 수 있습니다. 이 함수의 경우, contentView.frame 속성을 관찰하고 서브 뷰의 크기를 조정하면 효과가 있습니다.CALayer의 shadowPath 속성을 애니메이트하는 동안 사용자 상호 작용을 사용 중지하는 방법

UICollectionViewCell에는 CALayer을 사용하는 그림자가 있습니다. 그래서 같은 셀의 프레임으로 CAAnimation으로 그림자의 크기를 조절해야합니다.

하지만 CAAnimation 애니메이션 중에 셀 반복을 터치하면 액세스가 잘못됩니다.

물론 저는 userInteractionEnabled 속성 및 애니메이션 대리자를 사용하려고했지만 작동하지 않습니다.

어떤 아이디어가 있습니까?

관찰 코드 :

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if ([self.contentView isEqual:object]) { 
     // Change subviews frame 
     // Code.... 

     // Shadow Path 
     self.userInteractionEnabled = NO; 

     CGPathRef newShadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:kCornerRadius].CGPath; 
     NSArray *animationKeys = [self.layer animationKeys]; 

     if ([animationKeys count]&&[[animationKeys objectAtIndex:0] isKindOfClass:[NSString class]]) { 

      NSString *animationKey = [animationKeys objectAtIndex:0]; 
      CAAnimation *animation = [self.layer animationForKey:animationKey]; 

      CABasicAnimation *newAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; 
      newAnimation.duration = animation.duration; 
      newAnimation.toValue = [NSValue valueWithPointer:newShadowPath]; 
      newAnimation.timingFunction = animation.timingFunction; 
      newAnimation.delegate = self; 
      newAnimation.removedOnCompletion = NO; 

      [self.layer addAnimation:newAnimation forKey:@"shadowPath"]; 
     } 
     self.layer.shadowPath = newShadowPath; 
    } 
} 

여기에 애니메이션 대표 : 어떤 사용자 상호 작용을 중지하려면

#pragma mark - CAAnimation delegate 
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { 
    self.userInteractionEnabled = YES; 
} 
+0

당신은 (안전하게) KVO는 뷰의 프레임을 관찰 할 수 없습니다. 또한,'observeValueForKeyPath :'코드가 깨졌습니다. –

답변

0

하는 (실제로는 모든 것을 중지) 메인 쓰레드 선택기를 차단하여 문제 메소드를 호출 :

[self performSelectorOnMainThread:@selector(blockingMethod:) withObject:blockingMethodParam waitUntilDone:YES] 

이렇게하면 모든 것이 차단 될 때까지 중단됩니다. 메서드가 완전히 실행됩니다. 그러나 컨셉 접근 방식은 사용자가 기다리는 화면이 없을 때 특히 차단되는 UI를 원했기 때문에 그다지 좋지 않습니다.

참조 :

– performSelectorOnMainThread:withObject:waitUntilDone:

감사합니다,

hris.to