我想创建一个像推特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
}发布于 2014-02-18 22:18:56
像这样做
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下载
发布于 2014-02-18 22:19:51
尝试使用:
-(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.
}https://stackoverflow.com/questions/21856407
复制相似问题