2012-10-10 38 views

回答

5
// Create a empty view with the color white. 

UIView *flashView = [[UIView alloc] initWithFrame:window.bounds]; 
flashView.backgroundColor = [UIColor whiteColor]; 
flashView.alpha = 1.0; 

// Add the flash view to the window 

[window addSubview:flashView]; 

// Fade it out and remove after animation. 

[UIView animateWithDuration:0.05 animations:^{  flashView.alpha = 0.0; }  completion:^(BOOL finished) { [flashView removeFromSuperview];  }  ]; 
1

一個簡單的方法是在當前視圖(或UIWindow)上將白色UIView的alpha設置爲0。然後,應用閃光效果,可能是這樣的:

-(void)flashEffect { 

    // Show it suddenly 
    [self.flashSubview setAlpha:1.0]; 

    // Fade it out 
    [UIView animateWithDuration:0.5 
        animations:^{ 
         [self.flashSubview setAlpha:0.0]; 
        } 
        completion:^(BOOL finished){}]; 
} 
+0

@DrummerB感謝編輯和改進我的格式化:-) – atxe

1

一切的頂部添加全屏白色UIView和動畫的透明度。

// Create a fullscreen, empty, white view and add it to the window. 
UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 
UIView *flashView = [[UIView alloc] initWithFrame:window.bounds]; 
flashView.backgroundColor = [UIColor whiteColor]; 
flashView.alpha = 1.0f; 
[window addSubview:flashView]; 

// Fade it out and remove after animation. 
[UIView animateWithDuration:0.05f animations:^{ 
    flashView.alpha = 0.0f; 
} completion:^(BOOL finished) { 
    [flashView removeFromSuperview]; 
}]; 
+0

的方式,這是完美的,謝謝:) –