3
我在单元格子视图上添加运动效果。第一次它的工作正常。 但是当单元重新使用。运动效果不行....UIMotionEffect同时不能在UICollectionViewCell中工作
- (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;
}
,如果我想隐藏此子视图。并在展示之后。那么运动效果没用
processingCell.coustomView.hidden = YES;
processingCell.coustomView.hidden = NO;
我尝试使用此调试动作效果.the子视图暂停
PO [UIView的_motionEffectEngine]
https://github.com/sipdar/parallax-effect-Bug
您应该提供更多信息,例如:你有什么尝试,什么是错误,日志,... – Kay
为什么它的价值,我做了非常相似的事情,也发现它不起作用。你的代码并没有防范多次添加到单元格中的相同运动效果(当单元格被重用时),你应该这样做。我正在这样做,但我仍然遇到同样的问题。 – Benjohn