0

使用UIView animateWithDuration,我将UITableViewalpha 设置为 0,以便它在消失的动画中消失。但是,我注意到当UITableView褪色时,每个单元格上的某些区域在褪色前会变黑。如果有图像,它后面的整个区域在淡入淡出时会变黑,通常左右边缘的插入空间都会变黑。我已经尝试将子视图的所有背景颜色设置UITableViewCell为白色,但它仍然不起作用。

这个 tableview 没有嵌入到 UITableViewController 中。相反,它是一个单独的浮动 tableView,我将其用作菜单。

以下是它褪色时发生的情况的示例:

在此处输入图像描述

这也是我正在使用的代码

[UIView animateWithDuration:ImageViewControllerBarsAnimationDuration delay:0 options: UIViewAnimationOptionAllowUserInteraction animations:^
    {
            if (self.menu.superview)
            {
                self.menu.alpha = 0;
            }
    } 
completion:^(BOOL finished)
{
            if (self.menu.superview)
            {
                [self.menu removeFromSuperview];
                self.menu.alpha = 1;
            }   
}];

+

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (tableViewCell == nil) 
    {
        tableViewCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    }

    [[tableViewCell textLabel] setFont:[UIFont fontWithName: @"Helvetica-Bold" size: 17]];
    [[tableViewCell textLabel] setText: [self.menuItems objectAtIndex:0]];
    [[tableViewCell imageView] setImage: [self.menuItems objectAtIndex:1]];

    return tableViewCell;
}
4

2 回答 2

0

DTS给了我一个解决方案,必须做到以下几点:

self.myTableView.backgroundView = nil;
self.myTableView.backgroundColor = [UIColor clearColor];

然后在cellForRowAtIndexPath方法内部必须这样做:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kOneCellID = @"cellID";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kOneCellID];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kOneCellID] autorelease];
        cell.backgroundView = [[UIView alloc] init];
        cell.backgroundView.backgroundColor = [UIColor whiteColor];

    }

    ...
}
于 2012-07-27T22:26:08.513 回答
-4

什么是self.menu?如果你把 tableView 放在它的位置,它工作得很好。

[UIView animateWithDuration:ImageViewControllerBarsAnimationDuration delay:0 options: UIViewAnimationOptionAllowUserInteraction animations:^
    {
            if (tableView.superview)
            {
                tableView.alpha = 0;
            }
    } 
completion:^(BOOL finished)
{
            if (tableView.superview)
            {
                [tableView removeFromSuperview];
                tableView.alpha = 1;
            }   
}];
于 2012-06-29T06:11:35.377 回答