实际上,我有一个要在tableview单元格内的视图上应用阴影。该视图的高度是动态的(基于内容),这意味着tableview单元格是其自身大小的单元格。在iOS 13和xcode 11之前,我的代码可以完美运行,因为tableview单元的“ setSelected”方法返回单元的所有子视图的完美大小。在iOS 13和xcode 11中,所有子视图的tableview单元格的“ setSelected”方法返回的大小与xib中的设置相同。
使用下面的代码在视图上应用阴影:-
// Below method return correct size of view_margin (UIView) after content update in xcode 12 , but in xcode 13 below method return view_margin size same as size define in xib means not update size based on content
// Below method is tableview cell method
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.view_margin.bounds];
self.view_margin.layer.shadowColor = [UIColor blackColor].CGColor;
self.view_margin.layer.shadowOffset = CGSizeMake(0.0, 2.0);
self.view_margin.layer.shadowOpacity = 0.2;
self.view_margin.layer.shadowPath = shadowPath.CGPath;
self.view_margin.layer.masksToBounds = NO;
}
仅在xcode 11和iOS 13中会出现此问题
尝试一下:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.view_margin.bounds];
self.view_margin.layer.shadowColor = [UIColor blackColor].CGColor;
self.view_margin.layer.shadowOffset = CGSizeMake(0.0, 2.0);
self.view_margin.layer.shadowOpacity = 0.2;
self.view_margin.layer.shadowPath = shadowPath.CGPath;
self.view_margin.layer.masksToBounds = NO;
});
}