通过点击TableCell的图像,全屏图像

时间:2014-04-14 06:50:50

标签: ios objective-c uitableview fullscreen

我正在尝试显示自定义UITableViewCell中包含的较小图片的全屏图片。我的代码与this article

高度相关

顺便说一下,在这个例子中,框架:[[UIScreen mainScreen] bounds]对我来说不是好事。这是我所拥有的UIScrollView的界限。我这是在创建每个单元格时直接通过单元格内的变量添加主屏幕。所以我已经定制了前面的例子:

//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的框架。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

它可以采用全屏幕框架,因为它的父视图是scrollView。以模态方式显示视图或以某种方式直接在视图控制器的主视图下移动imageView。

答案 1 :(得分:0)

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

UIImageView添加点按提示,并将此bannerTapped添加为选择器

     //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;
            }