【发布时间】:2014-08-05 23:48:48
【问题描述】:
我正在尝试让我的 collectionview 单元格/uiimageview 在点击图像时全屏显示。我正在使用动画并从 didSelectItemAtIndexPath 执行此操作,一切正常并且看起来很棒,除了 imageview 根本没有改变大小,而且显然没有像我想要的那样全屏显示。我可以看到动画正在工作,但是这一切都发生在单元格预先存在的大小内,因此,图像被裁剪了。我希望它在点击时全屏显示,类似于它在 FB 中点击照片时的工作方式。感谢任何帮助!这是我的代码...
@interface BaseViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UITextFieldDelegate> {
CGRect prevFrame;
}
@property (nonatomic) BOOL isFullScreen;
- (void)updateUI;
@end
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
ImageViewCell *selectedCell = (ImageViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
NSLog(@"didSelectItemAtIndexPath");
if (!self.isFullScreen) {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
NSLog(@"starting animiation!");
prevFrame = selectedCell.imageView.frame;
selectedCell.imageView.center = self.view.center;
selectedCell.imageView.backgroundColor = [UIColor blackColor];
//[selectedCell.imageView setFrame:[[UIScreen mainScreen] bounds]];
[selectedCell.imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}completion:^(BOOL finished){
self.isFullScreen = YES;
}];
return;
} else {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
[selectedCell.imageView setFrame:prevFrame];
selectedCell.imageView.backgroundColor = [UIColor colorWithRed:0.62 green:0.651 blue:0.686 alpha:1];
}completion:^(BOOL finished){
self.isFullScreen = NO;
}];
return;
}
}
【问题讨论】:
标签: ios uiimageview uicollectionview fullscreen