Advertisement
Guest User

Untitled

a guest
Jul 12th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)graduallyAdjustBrightnessToValue:(CGFloat)endValue
  2. {
  3.     CGFloat startValue = [[UIScreen mainScreen] brightness];
  4.  
  5.     CGFloat fadeInterval = 0.01;
  6.     double delayInSeconds = 0.005;
  7.     if (endValue < startValue)
  8.         fadeInterval = -fadeInterval;
  9.  
  10.     CGFloat brightness = startValue;
  11.     while (fabs(brightness-endValue)>0) {
  12.  
  13.         brightness += fadeInterval;
  14.  
  15.         if (fabs(brightness-endValue) < fabs(fadeInterval))
  16.             brightness = endValue;
  17.  
  18.         dispatch_time_t dispatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  19.         dispatch_after(dispatchTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  20.             [[UIScreen mainScreen] setBrightness:brightness];
  21.         });
  22.     }
  23.     UIView *finalDarkScreen = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] keyWindow].bounds];
  24.     finalDarkScreen.backgroundColor = [UIColor blackColor];
  25.     finalDarkScreen.alpha = 0.3;
  26.  
  27.     //add it to the main window, but with no alpha
  28.     [[[UIApplication sharedApplication] keyWindow] addSubview:finalDarkScreen];
  29.  
  30.     [UIView animateWithDuration:1.0f
  31.                           delay:0.0f
  32.                         options:UIViewAnimationOptionCurveEaseOut
  33.                      animations:^{
  34.                          finalDarkScreen.alpha = 1.0f;
  35.                      }
  36.                      completion:^(BOOL finished){
  37.                          if (finished) {
  38.                              //DIE
  39.                         AudioServicesPlaySystemSound(1521);
  40.                         sleep(1);
  41.                              pid_t pid;
  42.                              const char* args[] = {"killall", "-9", "backboardd", NULL};
  43.                              posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
  44.                          }
  45.                      }];
  46. }
  47.  
  48. -(BOOL)prefersStatusBarHidden {
  49.     return YES;
  50. }
  51.  
  52. - (void)respring {
  53.     //make a visual effect view to fade in for the blur
  54.     [self.view endEditing:YES]; //save changes to text fields and dismiss keyboard
  55.  
  56.     UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  57.  
  58.     UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  59.  
  60.     visualEffectView.frame = [[UIApplication sharedApplication] keyWindow].bounds;
  61.     visualEffectView.alpha = 0.0;
  62.  
  63.     //add it to the main window, but with no alpha
  64.     [[[UIApplication sharedApplication] keyWindow] addSubview:visualEffectView];
  65.  
  66.     //animate in the alpha
  67.     [UIView animateWithDuration:3.5f
  68.                           delay:0.0f
  69.                         options:UIViewAnimationOptionCurveEaseOut
  70.                      animations:^{
  71.                          visualEffectView.alpha = 1.0f;
  72.                      }
  73.                      completion:^(BOOL finished){
  74.                          if (finished) {
  75.                              NSLog(@"Squiddy says hello");
  76.                              //call the animation here for the screen fade and respring
  77.                              [self graduallyAdjustBrightnessToValue:0.0f];
  78.                          }
  79.                      }];
  80.  
  81.     //sleep(15);
  82.  
  83.     //[[UIScreen mainScreen] setBrightness:0.0f]; //so the screen fades back in when the respringing is done
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement