셀 하위 뷰에 동작 효과를 추가합니다. 처음으로 잘 작동합니다. 하지만 셀 재사용. 모션 효과가 작동하지 ....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;
쓸모 모션 효과는 내가 국지적 인 서브 뷰가
포 일시 중단이 디버그 모션 효과를 사용하려고 [UIView의 _motionEffectEngine]
https://github.com/sipdar/parallax-effect-Bug
무엇을 시도 했습니까? 오류, 로그, 내용은 무엇입니까 ... – Kay
가치가있는 부분에 대해 저는 꽤 비슷한 것을하고 있으며 효과가 없다는 것을 발견했습니다. 코드가 셀에 여러 번 추가 될 때 (셀 재사용시) 동일한 동작 효과를 지키지 않아도됩니다. 나는 그것을하고 있고, 나는 여전히 같은 문제를 겪고있다. – Benjohn