1

我有一个 TableViewHeader 并想要对其进行动画处理,因此当我的表中有行时它看起来正在缩小。我尝试了很多东西,但它不想移动。控制台输出显示它已调整大小,但我仍然在屏幕上看到它正常。

为什么动画不起作用?我忽略了什么吗?

- (void)setProperHeader
{
    UIView *tempView = nil;
    CGRect offsets;
    if ([appointmentsList count] == 0) {
        NSLog(@"List Count 0");
        tempView = [[self.storyboard instantiateViewControllerWithIdentifier:@"ExistingAppointmentsViewController"] viewWithTag:400];
        offsets = CGRectMake(tempView.frame.origin.x, tempView.frame.origin.y, tempView.frame.size.width, tempView.frame.size.height);
        tempView.frame = CGRectMake(offsets.origin.x, offsets.origin.y, offsets.size.width, 0);
    } else {
        NSLog(@"List Count is %i", [appointmentsList count]);
        tempView= self.tableView.tableHeaderView;
        offsets = CGRectMake(tempView.frame.origin.x, tempView.frame.origin.y, tempView.frame.size.width, 0);
    }
    NSLog(@"TableView Frame: %@", NSStringFromCGRect(self.tableView.tableHeaderView.frame));
    NSLog(@"Offsets %@", NSStringFromCGRect(offsets));
    NSLog(@"Temp: %@", tempView);
//    if (tempView != self.tableView.tableHeaderView) {
        [self.tableView setTableHeaderView:tempView];
        [UIView animateWithDuration:1.0f
                         animations:^{
                             tempView.frame = offsets;
                         }
                         completion:^(BOOL finished) {
                             NSLog(@"Complete tempView: %@", tempView);
                             NSLog(@"Complete tableHeader: %@", self.tableView.tableHeaderView);
                             [self.tableView setNeedsLayout];
                             [self.tableView reloadData];
                         }];

//    }
}

[self.tableView setNeedsLayout]其添加为测试,以查看是否可以使其正常工作。

控制台输出

2013-09-25 16:04:32.301 App[63910:a0b] List Count is 2
2013-09-25 16:04:32.301 App[63910:a0b] TableView Frame: {{0, 0}, {320, 91}}
2013-09-25 16:04:32.301 App[63910:a0b] Offsets {{0, 0}, {320, 0}}
2013-09-25 16:04:32.302 App[63910:a0b] Temp: <UIView: 0xa568560; frame = (0 0; 320 91); autoresize = W+H; tag = 400; layer = <CALayer: 0xa5685c0>>
2013-09-25 16:04:33.313 App[63910:a0b] Complete tempView: <UIView: 0xa568560; frame = (0 0; 320 0); autoresize = W+H; tag = 400; layer = <CALayer: 0xa5685c0>>
2013-09-25 16:04:33.313 App[63910:a0b] Complete tableHeader: <UIView: 0xa568560; frame = (0 0; 320 0); autoresize = W+H; tag = 400; layer = <CALayer: 0xa5685c0>>
4

0 回答 0