我在 UITableViewCell
中有一个 UIImageView
并希望将其展开以填满全屏,我已经设置了我的 UIGestureRecognizer
并正在使用扩展框架的代码:
[UIView animateWithDuration:1.0 animations:^{
[self.ImageView setFrame:[[UIScreen mainScreen] applicationFrame]];
}];
但是 UIImageView
只会展开以填充 UITableViewCell
而不会填充全屏。
任何帮助将不胜感激。
最佳答案
cells clipsToBounds is set to Yes, so view outside the cell bound will not visible
以下方法将帮助您将单元格中的图像全屏显示,然后将其放回原处。
你需要在imageView中添加gestureRecognizer,并将选择器设置为cellImageTapped
声明 UIImageView *temptumb,fullview;作为实例变量。
- (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;
}
关于ios - 从 UITableViewCell 将 UIImageView 扩展到全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242805/