通过点击TableCell的图像来显示全屏图像 [英] FullScreen image through tap on TableCell's image

查看:79
本文介绍了通过点击TableCell的图像来显示全屏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从自定义UITableViewCell中包含的较小图片中显示全屏图片.我的代码与本文高度链接

I'm trying to show a fullscreen picture from a smaller one included in a custom UITableViewCell. My code is highly linked to this article

在这个例子中,顺便说一句:[[UIScreen mainScreen] bounds]帧对我来说不是好帧.这是我所拥有的UIScrollView范围.这是在创建每个单元格时直接通过单元格内部的变量添加主屏幕.因此,我已经像这样自定义了前面的示例:

By the way, in this example, the frame : [[UIScreen mainScreen] bounds]is not the good one for me. It's the an UIScrollView's bounds that I've got. I this to add the main screen through a variable inside the cell directly when each cell is created. So I've customized the previous example like this :

//viewDidLoad
self.globalView.frame = [[UIScreen mainScreen] bounds];

//cellForRowAtIndexPath
[cell setFullScreenView:self.globalView];

//fullScreenMethod
if (!isFullScreen) {
    [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
        //save previous frame
        prevFrame = imageView.frame;
        [imageView setFrame:self.fullScreenView.frame];
    }completion:^(BOOL finished){
        isFullScreen = YES;
    }];
    return;
}

我的问题是imageView的新帧不是全屏,而仍然是UIScrollView的全屏.

My problem is that the imageView's new frame is not a full screen but still the UIScrollView's one.

谢谢您的帮助!

推荐答案

最好的方法是创建一个临时UIImageView并全屏显示, 对于动画,只需将临时UIImageView添加到图像视图所在的位置,并将其设置为全屏动画,然后对普通图像进行反转

Best approach is create one temporary UIImageView and Show it in full screen, For animation simply add the temporary UIImageView to location where the image view exists and animate it to full-screen and do revers for normal

将点击手势添加到UIImageView并将此bannerTapped添加为选择器

Add tap gesture to UIImageView and add this bannerTapped as selector

     //This will create a temporary imaget view and animate it to fullscreen
            - (void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
                NSLog(@"%@", [gestureRecognizer view]);
                //create new image
                temptumb=(UIImageView *)gestureRecognizer.view;

                //fullview is gloabal, So we can acess any time to remove it
                fullview=[[UIImageView alloc]init];
                  [fullview setContentMode:UIViewContentModeScaleAspectFit];
                [fullview setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bckgrd.png"]]];
                fullview.image = [(UIImageView *)gestureRecognizer.view image];
                    CGRect point=[self.view convertRect:gestureRecognizer.view.bounds fromView:gestureRecognizer.view];
                [fullview setFrame:point];

                [self.view addSubview:fullview];
                [UIView animateWithDuration:0.5
                                 animations:^{
                                     [fullview setFrame:CGRectMake(0,
                                                                   0,
                                                                   self.view.bounds.size.width,
                                                                   self.view.bounds.size.height)];
                                 }];
                UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullimagetapped:)];
                singleTap.numberOfTapsRequired = 1;
                singleTap.numberOfTouchesRequired = 1;
                [fullview addGestureRecognizer:singleTap];
                [fullview setUserInteractionEnabled:YES];
            }

        //This will remove the full screen and back to original location.

            - (void)fullimagetapped:(UIGestureRecognizer *)gestureRecognizer {

                CGRect point=[self.view convertRect:temptumb.bounds fromView:temptumb];

                gestureRecognizer.view.backgroundColor=[UIColor clearColor];
                [UIView animateWithDuration:0.5
                                 animations:^{
                                     [(UIImageView *)gestureRecognizer.view setFrame:point];
                                 }];
                [self performSelector:@selector(animationDone:) withObject:[gestureRecognizer view] afterDelay:0.4];

            }

//Remove view after animation of remove
            -(void)animationDone:(UIView  *)view
            {
                //view.backgroundColor=[UIColor clearColor];
                [fullview removeFromSuperview];
                fullview=nil;
            }

这篇关于通过点击TableCell的图像来显示全屏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆