andersmoldin andersmoldin - 1 year ago 41
Objective-C Question

Display the "screenshot flash" as feedback to user

I'm very new to Objective-C and have just made my first app from scratch. It's a spelling app and I would like to display same white flash that is displayed on the screen when you take a screenshot if the user enters the wrong letter. How would I do that?

Answer Source
// 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];     }     ];