use*_*183 2 shadow uiview ios autoresizingmask
在自定义的tableview单元格中,我正在绘制一个带阴影的简单矩形,如下所示:
photoBorder = [[[UIView alloc] initWithFrame:CGRectMake(4, 4, self.frame.size.width-8, 190)] autorelease];
photoBorder.autoresizingMask = UIViewAutoresizingFlexibleWidth;
photoBorder.backgroundColor = [UIColor whiteColor];
photoBorder.layer.masksToBounds = NO;
photoBorder.layer.shadowOffset = CGSizeMake(0, 1);
photoBorder.layer.shadowRadius = 4;
photoBorder.layer.shadowOpacity = 1.0;
photoBorder.layer.shadowColor = [UIColor darkGrayColor].CGColor;
photoBorder.layer.shouldRasterize = YES;
photoBorder.layer.shadowPath = [UIBezierPath bezierPathWithRect:photoBorder.bounds].CGPath; // this line seems to be causing the problem
Run Code Online (Sandbox Code Playgroud)
这在视图首次加载时工作正常.但是,旋转设备时,阴影保持相同的大小.我真的很喜欢它延伸到"photoBorder"的新宽度.
我可以通过删除shadowPath来实现它,但是tableview会有明显的性能影响.
任何人都有任何关于在UIView上制作阴影的提示,可以延伸,而不会失去性能?
在搜索了几个小时而没有找到任何东西之后,我发布了这个.几分钟后找到答案.
对我来说,简单的解决方案似乎只是将shadowPath移动到layoutSubviews中.
- (void)layoutSubviews{
photoBorder.layer.shadowPath = [UIBezierPath bezierPathWithRect:photoBorder.bounds].CGPath;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1714 次 |
| 最近记录: |