【发布时间】:2013-09-03 20:38:40
【问题描述】:
我在使用自动布局在 iOS 6 应用程序中创建的 UIView 中添加阴影时遇到问题。
假设我有一个在 UIView 底部添加阴影的方法(这实际上是 UIView 的一个类别,因此可以重复使用):
- (void) addShadowOnBottom {
self.layer.shadowOffset = CGSizeMake(0, 2);
self.layer.shadowOpacity = 0.7;
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
}
当我在某些 UIViewController 的viewDidLoad 中调用此方法时,没有添加阴影,可能是由于所有限制,必须计算。
当我在viewWillAppear调用这个方法时也是一样的情况。
当我在viewDidAppear 中调用此方法时,它可以工作,但是当新视图出现时,有一小段时间没有阴影,它会在一段时间后出现。
如果我放弃设置 shadowPath 并删除行 self.layer.shadowPath 一切正常,但视图转换不流畅。
所以我的问题是在 iOS 6 中打开自动布局的情况下添加阴影以查看的正确方法是什么?
【问题讨论】:
-
我只是自己计算CGRect:CGPathRef path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 320, 480)].CGPath; [cview.layer setShadowPath:path];为我工作..
标签: ios objective-c xcode ios6 autolayout