首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从iOS表视图创建图像弹出窗口

从iOS表视图创建图像弹出窗口
EN

Stack Overflow用户
提问于 2014-02-18 22:14:00
回答 2查看 993关注 0票数 1

我想创建一个像推特iOS应用程序一样的弹出式图像,在那里你点击一个表视图中的图像,然后它全屏显示图像,这样你就可以更好地看到它。

我尝试了以下几种方法:

代码语言:javascript
运行
复制
         UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];  //this is called from the configurecell function

那么我调用的函数是:

代码语言:javascript
运行
复制
-(void)handleTap:(UIGestureRecognizer *)sender
{
CGPoint tapLocation = [sender locationInView:self.tableView];
NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];
Location *location = [self.fetchedResultsController objectAtIndexPath:tapIndexPath];
UIImage *overlayImage = [UIImage imageNamed:@"Default.PNG"];  //default.png is just the placeholder for now
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:overlayImage];
[self.tableView addSubview:overlayImageView];
}

这将导致图像弹出,但仅在点击图像的单元格上方。

编辑:

非常感谢您的投入。我发现我的问题是uiimageview被固定在表视图的顶部,因为CGRectMake是0,0,等等(0,0是左上角)。相反,我们需要将图像视图设置为当前可见区域,如下所示

代码语言:javascript
运行
复制
-(void)handleTap:(UIGestureRecognizer *)sender
 {
CGPoint tapLocation = [sender locationInView:self.tableView];
NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];
CGFloat distanceFromBottom = [self.tableView contentOffset].y;
UIImageView *imview=[[UIImageView alloc] initWithFrame:CGRectMake(0, distanceFromBottom, self.view.frame.size.width, self.view.frame.size.height)];
imview.backgroundColor=[UIColor blackColor];
imview.image = @"Default.PNG";
imview.tag=12345;  //give tag so we can find it and dismiss it
imview.contentMode=UIViewContentModeScaleAspectFit; //make sure image isn't stretched 
[self.view addSubview:imview];  //add the subview
self.tableView.scrollEnabled=NO; //make sure we can't scroll while image is popped out

 //now lets add a gesture recognizer to make sure we can dismiss the pop up uiimageview
 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissTap:)];
 tapGesture.numberOfTapsRequired = 1;
 tapGesture.cancelsTouchesInView=YES;
 imview.userInteractionEnabled = YES;
 [imview addGestureRecognizer:tapGesture];
 }


-(void)dismissTap:(UIGestureRecognizer *)sender
{
[[self.view viewWithTag:12345]removeFromSuperview];
self.tableView.scrollEnabled=YES;  //re enable scrolling
}
EN

回答 2

Stack Overflow用户

发布于 2014-02-18 22:18:56

像这样做

代码语言:javascript
运行
复制
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PopUP Title" 
                                                message:@"This is pop up window/ Alert" 
                                               delegate:nil 
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];

UIImageView *tempImageView=[[UIImageView alloc]initWithFrame:CGRectMake(20,20,50,50)];
tempImageView.image=[UIImage imageNamed:@"abc.png"];

[alert addSubView:tempImageView]

[alert show];

也可以从here github下载

票数 0
EN

Stack Overflow用户

发布于 2014-02-18 22:19:51

尝试使用:

代码语言:javascript
运行
复制
-(void)handleTap:(UIGestureRecognizer *)sender
{
CGPoint tapLocation = [sender locationInView:self.tableView];
NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];
Location *location = [self.fetchedResultsController objectAtIndexPath:tapIndexPath];
UIImage *overlayImage = [UIImage imageNamed:@"Default.PNG"];  //default.png is just the placeholder for now
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:overlayImage];
overlayImageView.frame = self.view.frame; // or set it as tableview.frame...set frame as per requirement.
[self.view addSubview:overlayImageView]; /You can also add a button to bring it back also.
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21856407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档