簡體   English   中英

iPad3上缺少圖層陰影(但可在模擬器中使用)

[英]Layer Shadow Missing on iPad3 (but works in Simulator)

我使用以下代碼在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上:完全沒有陰影。

在此處輸入圖片說明

知道怎么了嗎?

我找到了解決方案。 這與模擬器無關。 這是關於肖像與風景園林方向界限的回歸。 我必須將陰影路徑的設置移動到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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM