[英]Layer Shadow Missing on iPad3 (but works in Simulator)
I draw a shadow behind a UIView using the following code 我使用以下代码在UIView后面绘制阴影
self.view.layer.borderColor = [UIColor whiteColor].CGColor;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
self.view.layer.shadowOpacity = 1.0;
self.view.layer.shadowRadius = 25.0;
self.view.layer.shadowOffset = CGSizeMake(0, 3);
self.view.clipsToBounds = NO;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
[self.view.layer setShadowPath:shadowPath];
This works as supposed in the Simulator and on the iPhone5. 可以像在模拟器和iPhone5上那样工作。 However on my iPad3: No Shadow at all. 但是在我的iPad3上:完全没有阴影。
Any idea how come? 知道怎么了吗?
I found the solutions. 我找到了解决方案。 It wasn't about the Simulator. 这与模拟器无关。 It was about the return of bounds in portrait vs. landscapt orientation. 这是关于肖像与风景园林方向界限的回归。 I had to move the setting of the shadow path into the viewDidAppear and the didRotateFromInterfaceOrientation method to have the shadow render correctly in all possible startup orientations. 我必须将阴影路径的设置移动到viewDidAppear和didRotateFromInterfaceOrientation方法中,以使阴影在所有可能的启动方向上正确呈现。
-(void)viewDidAppear:(BOOL)animated{
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
[self.view.layer setShadowPath:shadowPath];
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
[self.view.layer setShadowPath:shadowPath];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.