我想做一个类似Facebook的iOS应用程序,当用户点击它时,它会从时间线上全屏显示图片。
更新:
我使用UICollectionView在单元格中显示图像,所以我似乎应该使用collectionView:didSelectItemAtIndexPath:方法?而且imageView在单元格中,所以我还可以直接扩展到全屏吗?
下面附上了几张图片:


发布于 2013-07-20 01:16:47
这是一个相当基本的解决方案。它假定您的集合单元格有一个UIImageView作为UICollectionViewCell contentView的唯一子视图。
#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];
}];
}发布于 2013-07-19 19:14:00
使用UITapGestureRecognizer,别忘了设置imageView.userInteractionEnabled = YES;,因为默认情况下图像没有UserInteraction。
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singleTap setNumberOfTapsRequired:1];
[imageView addGestureRecognizer:singleTap];
-(void)handleSingleTap:(id)sender {
// push you view here
//code for full screen image
}发布于 2013-07-19 19:28:43
我所理解的是,您在UIWebView中有您的图像这是我目前所拥有的,将UIWebViews委派设置为self,然后添加以下内容:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *URL = [request URL];
ImageViewer *imageView = [[[ImageViewer alloc] initWithNibName:@"ImageViewer" bundle:nil] autorelease];
imageView.imageURL = URL;
[self presentModalViewController:imageView animated:YES];
return NO;
} else {
return YES;
}
}只需像平常一样将图像作为html中的链接即可。如果你有不想在模型中加载的其他链接,那么你可以修改代码来检测被按下的链接是否指向一个图像,否则只需返回YES;
我在这里发布的网页视图有一点小问题(只是为了以防你遇到一些问题!) Code.
希望这能有所帮助!
https://stackoverflow.com/questions/17744689
复制相似问题