2014-10-31 60 views
0

我有一個動態單元大小的tableView,並且在重用單元格時無法調整陰影大小。此解決方案適用於iOS8,但不適用於iOS7。陰影第一次創建時,陰影也會基於單元大小正確顯示,但在單元格重新使用後會中斷陰影。iOS - 陰影不會正確調整大小

@implementation 

    static const CGFloat shadowWithInset = 2; 
    static const CGFloat shadowHeightOutset = 4; 

- (void)awakeFromNib { 
    CALayer *layer = self.innerView.layer; 

    layer.shadowOffset = CGSizeMake(1, 1); 
    layer.shadowRadius = 3.0f; 
    layer.shadowColor = [[UIColor gray] CGColor]; 
    layer.shadowOpacity = 0.8f; 
    //layer.shouldRasterize = YES; 
    //layer.rasterizationScale = [UIScreen mainScreen].scale; 

    CGSize size = layer.bounds.size; 
    layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(shadowWithInset, size.height-shadowHeightOutset, size.width-(shadowWithInset*2), shadowHeightOutset)].CGPath; 
} 

- (void)layoutSubViews { 
    [super layoutSubviews]; 

    CGSize size = self.innerView.bounds.size; 
    layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(shadowWithInset, size.height-shadowHeightOutset, size.width-(shadowWithInset*2), shadowHeightOutset)].CGPath; 
} 

@end 

回答

0

填充所有文本字段中的cellForRowAtIndexPath後,我結束了這樣:

[self setNeedsLayout]; 
[self layoutIfNeeded];