从 UITableViewCell 将 UIImageView 扩展到全屏

Expand UIImageView to full screen from within UITableViewCell(从 UITableViewCell 将 UIImageView 扩展到全屏)

本文介绍了从 UITableViewCell 将 UIImageView 扩展到全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableViewCell 中有一个 UIImageView 并希望将其展开以填满全屏,我已经设置了我的 UIGestureRecognizer 并正在使用扩展框架的代码:

I have a UIImageView within a UITableViewCell and want to expand it to fill the full screen, I have setup my UIGestureRecognizer and am using this code to expand the frame:

[UIView animateWithDuration:1.0 animations:^{
        [self.ImageView setFrame:[[UIScreen mainScreen] applicationFrame]];
}];

但是 UIImageView 只会展开以填充 UITableViewCell 而不会填充全屏.

However the UIImageView will only expand to fill the UITableViewCell and does not fill the full screen.

任何帮助将不胜感激.

推荐答案

cells clipsToBounds 设置为 Yes,因此在单元格边界之外的视图将不可见

cells clipsToBounds is set to Yes, so view outside the cell bound will not visible

以下方法将帮助您将单元格中的图像全屏显示,然后将其放回原处.

Following method will help u to get image in cell to full Screen then get it back to same place.

你需要在imageView中添加gestureRecognizer,并将选择器设置为cellImageTapped

You need to add gestureRecognizer to imageView and set selector as cellImageTapped

声明 UIImageView *temptumb,fullview;作为实例变量.

Declare UIImageView *temptumb,fullview; as instance variable.

- (void)cellImageTapped:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"%@", [gestureRecognizer view]);
    //create new image
    temptumb=(UIImageView *)gestureRecognizer.view;
    //temptumb=thumbnail;
    fullview=[[UIImageView alloc]init];
      [fullview setContentMode:UIViewContentModeScaleAspectFit];
    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];
}
- (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];

}

-(void)animationDone:(UIView  *)view
{
    [fullview removeFromSuperview];
    fullview=nil;
}

这篇关于从 UITableViewCell 将 UIImageView 扩展到全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从 UITableViewCell 将 UIImageView 扩展到全屏

基础教程推荐