Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent UITableViewCell flashing background when animating

I have a UIViewController with a custom background color. On top of it there's a UITableView with UITableViewCells that are semi-transparent (white color with opacity 0.5).

The issue I'm blaming about and the one I'm banging my head against the wall is in iOS 7, when you have a UITableViewCell with semi-transparent background and you try to delete/insert/moving rows (so relying on an animation effect) the entire UITableView with its cells flashing for just 0.1 second and set cells background to a more transparent one. This is very annoying.

The only thing I'm doing is set the background color of self.view with:

self.view.backgroundColor = [UIColor colorWithRed:0.4 green:0.5 blue:0.7 alpha:1];

and set the background color of cells with:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}

Here's a gif showing you the problem:

enter image description here

And here's the super simple project: https://github.com/socksz/TransparentCellFlashing

Please help me to solve this ridicolous issue! :P

like image 214
Fred Collins Avatar asked Dec 08 '13 21:12

Fred Collins


People also ask

How do I make an animated video transparent?

1 Answer 1. You need to go to the "Properties" panel, "Render" tab, subsection "Film" and check "Transparent". Also, keep in mind that animations should first be rendered to individual images, to avoid file corruption, and joined using something like Blender's Video Sequence Editor.

How do I Fade the background of an animation?

Let's start with the basics. A simple colour fade - you can use @keyframes to fade the background between as many colours as you need and use the percentages to determine how long the animation will stay on that colour before changing. Simple, easy to implement, and effective.

How do I preserve the alpha channel of an animation?

Also what video file do I have to use to preserve the alpha channel? You need to go to the "Properties" panel, "Render" tab, subsection "Film" and check "Transparent". Also, keep in mind that animations should first be rendered to individual images, to avoid file corruption, and joined using something like Blender's Video Sequence Editor.

How do I make a transparent alpha channel?

So how would I go about having a background that is transparent alpha channel and all? Also what video file do I have to use to preserve the alpha channel? You need to go to the "Properties" panel, "Render" tab, subsection "Film" and check "Transparent".


1 Answers

  1. Create a subclass of UITableViewCell(Such as named: CustomCell), and override the method in CustomCell.m :

    - (id)initWithCoder:(NSCoder *)aDecoder{
        self = [super initWithCoder:aDecoder];
        if(self){
            // Initialization code
            [self setBackgroundColor:[UIColor clearColor]];
            UIView * bgView = [[UIView alloc] initWithFrame:self.frame];
            [bgView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5]];
            [self addSubview:bgView];
        }
        return self;
    }
    
  2. Remove willDisplayCell method in MasterViewController.m

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
    }
    
  3. Change the cellForRowAtIndexPath method in MasterViewController.m

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    
  4. Change the cell's class type in storyboard enter image description here

Just have a try :D

enter image description here

like image 141
Joiningss Avatar answered Oct 17 '22 01:10

Joiningss