gpt4 book ai didi

ios - 触摸时如何使图像扩展到全屏?

转载 作者:可可西里 更新时间:2023-11-01 03:06:00 26 4
gpt4 key购买 nike

我想制作一个类似 Facebook 的 iOS 应用程序,当用户点击它时,它会从时间轴全屏显示图片。

更新:

我正在使用 UICollectionView 在单元格中显示图像,所以我似乎应该使用 collectionView:didSelectItemAtIndexPath: 方法?并且imageView在cell中,我还能直接展开全屏吗?

下面附上几张图片:

enter image description here

enter image description here

最佳答案

这是一个相当基本的解决方案。它假设您的集合单元有一个 UIImageView 作为 UICollectionViewCell contentView 的唯一 subview 。

#import <objc/runtime.h> // for objc_setAssociatedObject / objc_getAssociatedObject

...

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];

UIImageView* iv = cell.contentView.subviews.lastObject;

UIImageView* ivExpand = [[UIImageView alloc] initWithImage: iv.image];
ivExpand.contentMode = iv.contentMode;
ivExpand.frame = [self.view convertRect: iv.frame fromView: iv.superview];
ivExpand.userInteractionEnabled = YES;
ivExpand.clipsToBounds = YES;

objc_setAssociatedObject( ivExpand,
"original_frame",
[NSValue valueWithCGRect: ivExpand.frame],
OBJC_ASSOCIATION_RETAIN);

[UIView transitionWithView: self.view
duration: 1.0
options: UIViewAnimationOptionAllowAnimatedContent
animations:^{

[self.view addSubview: ivExpand];
ivExpand.frame = self.view.bounds;

} completion:^(BOOL finished) {

UITapGestureRecognizer* tgr = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector( onTap: )];
[ivExpand addGestureRecognizer: tgr];
}];
}

- (void) onTap: (UITapGestureRecognizer*) tgr
{
[UIView animateWithDuration: 1.0
animations:^{

tgr.view.frame = [objc_getAssociatedObject( tgr.view,
"original_frame" ) CGRectValue];
} completion:^(BOOL finished) {

[tgr.view removeFromSuperview];
}];
}

关于ios - 触摸时如何使图像扩展到全屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17744689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com