0

私のプロジェクトは使用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;
}
4

2 に答える 2

0

ユーザーの操作を停止したい場合 (実際にはすべてを停止します)、メイン スレッド セレクターをブロックして問題のメソッドを呼び出します。

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

このようにして、blockingMethod が完全に実行されるまですべてが停止するようにします。ただし、特に何らかの待機画面がない場合は、ユーザーがUIをブロックすることを望んでいないため、コンセプトのアプローチはあまり良くありません。

参照:

– performSelectorOnMainThread:withObject:waitUntilDone:

よろしく、

hris.to

于 2013-12-21T15:34:51.240 に答える