我从右向左滚动图像
我想为来自右边的每个单元格制作动画(ala Google +)
此动画可以基于Alpha或帧位置
如何实现?
答案 0 :(得分:1)
这可能不是您想要的动画,但这是我在UICollectionViewCell子类中所做的。当框架缩小到合适的尺寸时,这将在单元格中消失。我在setPhoto
内调用collectionView: cellForItemAtIndexPath:
方法。
@implementation HistoryCollectionViewCell
- (void)setPhoto:(Photo*)photo {
if(_photo != photo) {
_photo = photo;
}
// Set up the animations here
self.photoQueue.alpha = 0.0f;
self.cellContainerView.alpha = 0.0f;
CGRect currentFrame = self.cellContainerView.frame;
CGFloat width = currentFrame.size.width + 20;
CGFloat height = currentFrame.size.height + 20;
CGFloat originX = currentFrame.origin.x - 10;
CGFloat originY = currentFrame.origin.y - 10;
CGRect newFrame = CGRectMake(originX, originY, width, height);
self.cellContainerView.frame = newFrame;
dispatch_queue_t photoQueue = dispatch_queue_create("com.jeremyfox.SnapTo.photoQueue", NULL);
dispatch_async(photoQueue, ^{
__block UIImage* image = nil;
if (_photo) {
image = [Photo getImageAtPath:_photo.thumbnail];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (image) {
self.imageView.image = image;
// Perform the animations here
[UIView animateWithDuration:0.3f animations:^{
self.cellContainerView.alpha = 1.0f;
self.cellContainerView.frame = currentFrame;
}];
}
});
});
}