ITableViewCell内将UIImageView扩展为全屏

ITableViewCell内将UIImageView扩展为全屏

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

问题描述

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

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

然而 UIImageView 只会扩展为填充 UITableViewCell 并没有填满整个屏幕。



我们非常感谢任何帮助。


'的div类= h2_lin>解决方案

以下方法将帮助您将单元格中的图像设置为全屏,然后将其恢复到同一位置。



您需要将gestureRecognizer添加到imageView并将选择器设置为cellImageTapped



声明UIImageView * temptumb,fullview;如实例变量



   - (无效)cellImageTapped:(UIGestureRecognizer *)gestureRecognizer {
的NSLog(@%@ ,[gestureRecognizer view]);
//创建新图像
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
动画:^ {
[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];
}
- (无效)fullimagetapped:(UIGestureRecognizer *)gestureRecognizer {

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

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

}

- (无效)animationDone:(UIView *)查看
{
[fullview removeFromSuperview];
fullview = nil;
}


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

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

Any help would be much appreciated.

解决方案

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

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

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扩展为全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:19