Prevent iOS from taking screen capture of app before going into background

后端 未结 10 2664
Happy的楠姐
Happy的楠姐 2020-11-29 22:35

You all might know that iOS takes a screen shot of your application before throwing it into the background. This is usually for a better User experience like quick animation

10条回答
  •  Happy的楠姐
    2020-11-29 23:11

    Implementation with some animation while going in background and reverse action

       - (void)applicationWillResignActive:(UIApplication *)application
    {
         //     fill screen with our own colour
            UIView *colourView = [[UIView alloc]initWithFrame:self.window.frame];
            colourView.backgroundColor = [UIColor blackColor];
            colourView.tag = 1111;
            colourView.alpha = 0;
            [self.window addSubview:colourView];
            [self.window bringSubviewToFront:colourView];
    
            // fade in the view
            [UIView animateWithDuration:0.5 animations:^{
                colourView.alpha = 1;
            }];
    
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        // grab a reference to our coloured view
        UIView *colourView = [self.window viewWithTag:1111];
        // fade away colour view from main view
        [UIView animateWithDuration:0.5 animations:^{
            colourView.alpha = 0;
        } completion:^(BOOL finished) {
            // remove when finished fading
            [colourView removeFromSuperview];
        }];
    
     }
    

提交回复
热议问题