Search code examples
uitableviewios7transparency

iOS7 UITableViewCell background transparancy becomes opaque after a short pause


I have a UITableView which is presented modally over a view. One of the cells in the table view is deliberately transparent so that the view underneath is visable. The issue is that is IOS 7.1 the cell starts off transparent and then immediately becomes opaque. Under iOS 8 the transparent cell technique works perfectly.

Qn. Has anyone seen this and come up with a valid work-around?

Things I've tried

  • Adjusting cell.backgroundColor
  • Adjusting cell.backgroundView
  • Adjusting tableView.backgroundColor
  • Adjusting tableView.backgroundView

  • Setting tableView.opaque = YES;

  • Making the adjustments in tableView:cellForRowAtIndexPath:

  • Making the adjustments in tableView:willDisplayCell:forRowAtIndexPath:

  • Using full transparencies

  • Using partial transparencies
  • Using transparent images

  • [[UITableViewCell appearance] setBackgroundColor:[UIColor clearColor]];

Essentially as soon as any transparency is introduced into the background it changes (after a slight pause to become opaque).

enter image description here

To re-iterate under iOS7 the transparency is there very briefly (less than a 1/2 sec) then it turns opaque.

Here is a vimeo of the effect: Link


Solution

  • Rather than focusing on the tableview and it's cells, look at the presenting (bottom) view controller. I believe (although I can't find it officially documented at the moment) that when you do a standard modal presentation of one view controller over another, the presenting view controller's view is removed from the view hierarchy after presentation. Working with a trivial test app, the presenting view controller's -viewWillDisappear: is called and logging the key window's -recursiveDescription show the presenting view controller's view has been removed.

    However, if you use a custom transition, the presenting view controller's view is kept in place (presumably to allow for exactly this kind of transparency effect).

    EDIT: I've put together a quick example app (here: https://github.com/sjc/ViewControllerTransitionExample) to 1) illustrate the difference in behaviour between standard and custom modal presentation, and 2) to show how a basic UINavigationController subclass can be built to solve this issue (the technique is normally just applied to straight UIViewController subclasses).

    However... While this can be used to solve the issue in this case, it doesn't answer the 'what's going on here?' question, since the example doesn't reproduce exactly what you are seeing: the presenting view controller disappears on both iOS 7 and 8, and not just on 7, as described in the original question. Oh well.