Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent UITableviewcell from becoming transparent during reordering

I am trying to keep my uitableviewcells opaque during reorder animation - reason being that I am doing custom drawing of the cell in one view to enhance scroll performance, but doing this slows down the reorder animation significantly.

Any idea how to achieve this?

like image 474
Sean S Lee Avatar asked Feb 27 '11 09:02

Sean S Lee


2 Answers

For an excellent description of what is going on when the table is in dragging mode, see this answer.

I had a UITableViewStyleGrouped on iOS 7. In order to get the desired effect (non-transparent, white background), I had to follow Aaron's suggestion and bmovement's.

@interface ABCCell : UITableViewCell

@end

@implementation ABCCell

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.backgroundView = [UIView new];
        self.backgroundView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setAlpha:(CGFloat)alpha {
    [super setAlpha:1.0];
}

@end

Not doing either causes the view to have a 100% transparent background.

Setting just the background view causes the cell to have a 80% transparent white background.

Setting just the alpha causes the cell to have a black background (0% transparent).

Implementing both, gives you a white background (0% transparent).

like image 149
Senseful Avatar answered Sep 20 '22 06:09

Senseful


For some reason, my UITableViewCell subclass's drawRect wasn't being called when the reorder animation began, but adding this to my subclass worked for me:

- (void)setAlpha:(CGFloat)alpha {
    [super setAlpha:1.0f];
}
like image 34
bmovement Avatar answered Sep 19 '22 06:09

bmovement