【问题标题】:Layer Shadow Missing on iPad3 (but works in Simulator)iPad 上缺少图层阴影(但可在模拟器中使用)
【发布时间】:2013-03-01 23:27:10
【问题描述】:

我使用以下代码在 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];

这在模拟器和 iPhone5 上可以正常工作。但是在我的 iPad3 上:根本没有阴影。

知道怎么来的吗?

【问题讨论】:

    标签: ios objective-c quartz-graphics shadow


    【解决方案1】:

    我找到了解决方案。这与模拟器无关。这是关于纵向与横向边界的回归。我必须将阴影路径的设置移动到 viewDidAppeardidRotateFromInterfaceOrientation 方法中,以便在所有可能的启动方向上正确渲染阴影。

    -(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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多