Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 361
andersmoldin Avatar asked Jan 15 '23 08:01

andersmoldin


2 Answers

// 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];     }     ];
like image 79
james lobo Avatar answered Jan 25 '23 23:01

james lobo


Add a fullscreen white UIView on top of everything and animate its alpha.

// 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];
}];
like image 38
DrummerB Avatar answered Jan 25 '23 23:01

DrummerB