首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UICollectionViewCell中UIMotionEffect同时不起作用

在UICollectionViewCell中UIMotionEffect同时不起作用
EN

Stack Overflow用户
提问于 2014-02-26 18:20:22
回答 1查看 832关注 0票数 3

我在单元格子视图上添加了运动效果。第一次,它工作得很好。但是当细胞被重复使用时。动作效果不起作用...

代码语言:javascript
复制
- (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;

}

如果我想隐藏这个子视图。在展示它之后。那么动作效果就没用了。

代码语言:javascript
复制
processingCell.coustomView.hidden = YES;
processingCell.coustomView.hidden = NO;

我尝试使用此调试运动效果.the subView已挂起

po UIView _motionEffectEngine

https://github.com/sipdar/parallax-effect-Bug

EN

回答 1

Stack Overflow用户

发布于 2015-11-10 02:14:20

通过将UICollectionViewCell子类化,并在布局过程中移除并重新应用运动效果,我能够让它工作。示例:

代码语言:javascript
复制
- (void) layoutSubviews{
    [super layoutSubviews];
    [self addMotionEffectToView:self.contentView];
}

- (void) addMotionEffectToView:(UIView*) view{

    for (UIMotionEffect* effect in [view.motionEffects copy]){
        [view removeMotionEffect:effect];
    }
    ... add your motion effect
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22038302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档