내 프로젝트 사용 UICollectionView
및 UICollectionViewCell
을 터치하여 확장/축소 할 수 있습니다. 이 함수의 경우, 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;
}
당신은 (안전하게) KVO는 뷰의 프레임을 관찰 할 수 없습니다. 또한,'observeValueForKeyPath :'코드가 깨졌습니다. –