How to programmatically launch the screen?

After a long time searching, I have to refuse and ask.

Is it possible to use a flash screen (as when shooting with the "home" button + power button)?

If so, how?

Thanks in advance for your answers.

+4
source share
2 answers

Add a white full-screen UIView to the window and animate its alpha (play with a duration and animation curve to get the result you want):

-(void) flashScreen { UIWindow* wnd = [UIApplication sharedApplication].keyWindow; UIView* v = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)] autorelease]; [wnd addSubview: v]; v.backgroundColor = [UIColor whiteColor]; [UIView beginAnimations: nil context: nil]; [UIView setAnimationDuration: 1.0]; v.alpha = 0.0f; [UIView commitAnimations]; } 

Edit: Remember to delete this view after the animation ends.

+6
source

Like the answer provided by Max, but use UIView animateWithDuration instead

 - (void)flashScreen { // Make a white view for the flash UIView *whiteView = [[UIView alloc] initWithFrame:self.view.frame]; whiteView.backgroundColor = [UIColor whiteColor]; whiteView.alpha = 1.0; // Optional, default is 1.0 // Add the view [self.view addSubview:whiteView]; // Animate the flash [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut // Seems to give a good effect. Other options exist animations:^{ // Animate alpha whiteView.alpha = 0.0; } completion:^(BOOL finished) { // Remove the view when the animation is done [whiteView removeFromSuperview]; }]; } 

There are different versions of animateWithDuration, you can also use this shorter version if you do not need a delay and in the order with the default animation settings.

 [UIView animateWithDuration:1.0 animations:^{ // Animate alpha whiteView.alpha = 0.0; } completion:^(BOOL finished) { // Remove the view when the animation is done [whiteView removeFromSuperview]; }]; 
0
source

Source: https://habr.com/ru/post/1343100/


All Articles