1

我在我的应用程序中使用单个 UITableView。我根据行选择等更改 UITableView 的委托和数据源。

为了在用户四处移动时为过渡设置动画,我抓取了当前 UITableView 的图像,将图像放置在 UITableView 顶部的 UIImageView 中,在 UITableView 上重新加载数据,然后在动画过渡中移除 UIImageView。

代码如下:

-(void)showImageEditPageWithImageId:(NSString*)imageId
{
    UITableView* tableview = (UITableView*)[self.view viewWithTag:VIEWTAG_P1_MAINTABLEVIEW];

    UIImage* image = [HPSImageHelper imageWithView:tableview];
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:tableview.frame];
    imageView.tag = 336611;
    imageView.layer.borderWidth=1;
    imageView.layer.borderColor = [UIColor blueColor].CGColor;
    [imageView setImage:image];

    _tableViewController = [[HPSImageEditTableViewController alloc] initWithImageId:imageId];
    ((HPSImageEditTableViewController*)_tableViewController).callingController = self;    
    tableview.dataSource = _tableViewController;
    tableview.delegate = _tableViewController;

    [tableview reloadData];

    [tableview.superview addSubview:imageView];

    [NSTimer scheduledTimerWithTimeInterval:0.1
                                     target:self
                                   selector:@selector(removeCoveringImage)
                                   userInfo:nil
                                    repeats:NO];

}

-(void)removeCoveringImage
{
    UIView* imageView = [self.view viewWithTag:336611];

    [UIView transitionWithView:imageView
                      duration:0.9
                       options:UIViewAnimationOptionTransitionCurlUp
                    animations:^{
                        //Nothing here

                    }
                    completion:^(BOOL finished){

                        [imageView removeFromSuperview];
                    }
     ];

}

麻烦的是,UITableView 只有在转换完成后才会在视觉上刷新自己,所以新视图会突然跳入视图。

在我看来, UITableView 并没有刷新自己,因为它“知道”它实际上并不可见。

Is that what's happening, and if so how do I get the UITableView to redraw even though it is covered by the UIImageView?

Thanks.

4

1 回答 1

0

Try calling setNeedsDisplay on your table view after load data. If that doest help try add UIViewAnimationOptionLayoutSubviews option to your animation. If nether of those help, try to lower alpha of imageView only slightly enough(0.99 or 0.98 or 0.90) to force tableView to redraw before animation. Hope this helped

于 2012-09-25T14:49:39.300 回答