【发布时间】:2014-02-26 10:20:21
【问题描述】:
我在单元格子视图上添加运动效果。 第一次它工作得很好。 但是当细胞重复使用时。运动效果不起作用....
- (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;
我尝试使用这个调试运动效果。子视图被暂停
po [UIView _motionEffectEngine]
【问题讨论】:
-
您应该提供更多信息,例如您尝试了什么,错误是什么,日志,...
-
对于它的价值,我正在做一些非常相似的事情,但也发现它不起作用。您的代码没有防止将相同的运动效果多次添加到单元格中(当重新使用单元格时),您应该这样做。我正在这样做,但我仍然遇到同样的问题。
标签: ios ios7 parallax uicollectionviewcell core-motion