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:
And here's the super simple project: https://github.com/socksz/TransparentCellFlashing
Please help me to solve this ridicolous issue! :P
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.
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.
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.
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".
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;
}
Remove willDisplayCell method in MasterViewController.m
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}
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;
}
Change the cell's class type in storyboard
Just have a try :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With