用动画展开UITableViewCell

时间:2015-03-27 18:48:47

标签: objective-c uitableview uiview uiimageview

我尝试在UITableView中实施功能,其中UITableViewCell UIImageView展开以填充用户触摸单元格后的完整视图。

这是我正在使用的动画:

UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
UIImageView *imageView = [cell viewWithTag:1];
UIView *cellView = [cell viewWithTag:2];

CGRect rectInTableView = [_tableView rectForRowAtIndexPath:indexPath];

[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^(void)
                     {
                         imageView.frame = rectInTableView;
                         imageView.tag = 123;
                         [self.navigationController.view addSubview:imageView];
                         [imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+64)];
                         imageView.contentMode = UIViewContentModeScaleAspectFill;
                     }
                 completion:^(BOOL finished)
                     {}];

现在发生的事情是UIImageView跳到顶部然后展开。我希望它从细胞扩展。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

这可能会完成您尝试做的事情:

UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
UIImageView *imageView = [cell viewWithTag:1];
UIView *cellView = [cell viewWithTag:2];

CGRect rectInTableView = [_tableView rectForRowAtIndexPath:indexPath];
imageView.frame = rectInTableView;
imageView.tag = 123;
[self.navigationController.view addSubview:imageView];

[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^(void)
                     {
                         [imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+64)];
                         imageView.contentMode = UIViewContentModeScaleAspectFill;
                     }
                 completion:^(BOOL finished)
                     {}];