![](/img/trans.png)
[英]collectionviewcell didSelectItemAtIndexPath/didDeselectItemAtIndexPath not responding for specific cells
[英]Need to shake a collectionviewcell on didselectitematindexpath in ios
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform"] ;
anim.values = @[ [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-10.0f, 0.0f, 0.0f) ], [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(10.0f, 0.0f, 0.0f) ] ] ;
anim.autoreverses = YES;
anim.repeatCount = 2.0f;
anim.duration = 0.1f;
[cell.layer addAnimation:anim forKey:nil] ;
我編寫上面的代碼以在選擇時搖動集合視圖單元格。 當我在查看屏幕后第一次執行此操作時,集合視圖單元格的框架不匹配。當我再次訪問該視圖時,它工作正常。 請幫助我,為什么添加動畫后第一次創建問題,如果我刪除動畫,那么第一次也沒有不匹配,但我需要觸摸動畫。
當我再次在此視圖上再次訪問並執行部分時,沒有框架失配。僅在第一次訪問時出現第一次選擇的問題。
我得到了這個問題的解決方案,為什么集合視圖單元格的框架不匹配。 這是由於ToastView引起的。 我正在通過烤面包顯示超出圖像的消息。 現在,我使用警報視圖,並且可以正常工作。
您可以使用以下代碼進行搖動查看。
#pragma mark
#pragma mark - ANIMATION SHAKE
- (void)shake:(UIView *)shakeView {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.duration = 0.6;
animation.values = @[ @(-10), @(10), @(-10), @(10), @(-5), @(5), @(-2.5), @(5), @(0) ];
[shakeView.layer addAnimation:animation forKey:@"shake"];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.