2015-09-18 71 views
-2

我有一個觀點,我想用一個模糊來遮擋它,並讓它具有動畫效果。我在故事板中添加了名爲blurField的UIVisualEffectView。這是我一起入侵的,有沒有更乾淨的方法來做到這一點?謝謝!如何讓UIVisualEffectView淡入動畫?

-(void)viewDidLoad { 
    [super viewDidLoad]; 
    self.blurField.alpha = 0.0; 
    [self performSelector:@selector(fillInBlur) withObject:nil afterDelay:3.0]; 
} 

-(void)fillInBlur { 
    self.blurField.alpha = 0.1; 
    [self performSelector:@selector(fillInBlur1) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur1 { 
    self.blurField.alpha = 0.2; 
    [self performSelector:@selector(fillInBlur2) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur2 { 
    self.blurField.alpha = 0.3; 
    [self performSelector:@selector(fillInBlur3) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur3 { 
    self.blurField.alpha = 0.4; 
    [self performSelector:@selector(fillInBlur4) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur4 { 
    self.blurField.alpha = 0.5; 
    [self performSelector:@selector(fillInBlur5) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur5 { 
    self.blurField.alpha = 0.6; 
    [self performSelector:@selector(fillInBlur6) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur6 { 
    self.blurField.alpha = 0.7; 
    [self performSelector:@selector(fillInBlur7) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur7 { 
    self.blurField.alpha = 0.8; 
    [self performSelector:@selector(fillInBlur8) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur8 { 
    self.blurField.alpha = 0.9; 
    [self performSelector:@selector(fillInBlur9) withObject:nil afterDelay:0.03]; 
} 

-(void)fillInBlur9 { 
    self.blurField.alpha = 1.0; 
} 

回答

4

在iOS 8中,視覺效果視圖不透明度的動畫是非法和不可能的。這是因爲其實施的特殊方式。

在iOS 9中,您可以直接爲模糊本身製作動畫。從UIVisualEffectView開始,其effectnil,然後將其effect設置爲animations:塊內的UIBlurEffect。模糊會將自身變爲現實。

仍然有一些限制,但運行時會打電話給你清楚,如果你打他們。有關此主題的WWDC 2015視頻很棒。

+0

感謝您的幫助@matt! – tahoecoop