i add a motion effect to the cell sub. the first time it worked fine. but when the cell is reused. motion effect does not work ....
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
testcell *processingCell = (testcell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-kMotionEffectRelativeValue );
horizontalMotionEffect.maximumRelativeValue = @(kMotionEffectRelativeValue );
UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
verticalMotionEffect.minimumRelativeValue = @(-kMotionEffectRelativeValue );
verticalMotionEffect.maximumRelativeValue = @(kMotionEffectRelativeValue );
group = [[UIMotionEffectGroup alloc] init];
group.motionEffects = @[horizontalMotionEffect,verticalMotionEffect];
});
if (!processingCell.coustomView) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
view.center = processingCell.contentView.center;
view.backgroundColor =[UIColor blackColor];
[processingCell addSubview:view];
processingCell.coustomView = view;
}
processingCell.coustomView.hidden = YES;
processingCell.coustomView.hidden = NO;
[processingCell.coustomView addMotionEffect:group];
return processingCell;
}
if I want to hide this view. and after the show. then useless motion effect
processingCell.coustomView.hidden = YES;
processingCell.coustomView.hidden = NO;
I am trying to use this debugging motion effect. Subview paused
po [UIView _motionEffectEngine]
https://github.com/sipdar/parallax-effect-Bug
source
share