简体   繁体   中英

FullScreen image through tap on TableCell's image

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

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

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

Thank you for your help !

It can't take a full screen frame because its parent view is the scrollView. Either show view modally or somehow move imageView directly under view controller's main view.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM