私のプロジェクトは使用UICollectionView
しておりUICollectionViewCell
、タッチして展開/折りたたむことができます。この関数では、contentView.frame
プロパティを監視してサブビューのサイズを変更していますが、うまく機能します。
問題は、 を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;
}