我想创建一个类似于Twitter iOS应用程序的弹出图像,在该图像上单击表格视图中的图像,然后全屏显示图像,以便您可以更好地看到它。从iOS桌面视图创建图像弹出
我尝试以下:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; //this is called from the configurecell function
然后我调用该函数是:
-(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,是左上角)。相反,我们需要将图像视图设置为当前可视区域,像这样
-(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
}
感谢您的回复,这可能是我最终这样做的方式。我希望能找到一种不是一种警觉的方式,但这可能是最简单/最好的方式。顺便说一句,要做到这一点,您可能需要调整图像大小。 – user2057434
我发现我遇到的问题。这个工作非常完美,但是它会将展开后的图像放在tableview的顶部(如果您正在向下滚动,这可能会看不见)。我通过获取我们正在查看的y位置来修复它(请参阅下面的答案) – user2057434