Simulate Flash Animation Screenshots on iOS

Im looking for a way to copy the blink animation that plays when I press the home + lock button.

Does anyone know if this animation is available?

+7
ios
source share
5 answers

On an iOS device, you take a picture when you press the "home + lock" button and the screen blinks white. Do you mean this effect? If yes, try the following:

Add a UIView with a white background to your view hierarchy so that it spans the entire screen. Then run an animation that reduces the opacity of this view to zero. When finished, remove the view from your supervisor:

 [UIView animateWithDuration: 0.5 animations: ^{ whiteView.alpha = 0.0; } completion: ^(BOOL finished) { [whiteView removeFromSuperview]; } ]; 
+10
source share

Try:

 [UIView animateWithDuration:1 animations:^{ self.view.backgroundColor = [UIColor blackColor]; for (UIView *view2 in self.view.subviews) { view2.backgroundColor = [UIColor blackColor]; } }]; [UIView animateWithDuration:1 animations:^{ self.view.backgroundColor = [UIColor whiteColor]; for (UIView *view2 in self.view.subviews) { view2.backgroundColor = [UIColor whiteColor]; } }]; 
+3
source share

I found a very simple way to emulate the screenshot that Apple Flash uses. I wish everyone tried at least once.

 UIView * flashView = [[UIView alloc] initWithFrame:self.view.frame]; flashView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:flashView]; [UIView animateWithDuration:1 delay:0.3 options:0 animations:^{ flashView.alpha = 0; } completion:^(BOOL finished) { [flashView removeFromSuperview]; }]; } 
+2
source share

These examples gave me inspiration, but gave me the desired effect. This is my attempt, it looks pretty close to the real deal.

 func mimicScreenShotFlash() { let aView = UIView(frame: self.view.frame) aView.backgroundColor = UIColor.whiteColor() self.view.addSubview(aView) UIView.animateWithDuration(1.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in aView.alpha = 0.0 }, completion: { (done) -> Void in aView.removeFromSuperview() }) } 
0
source share

Two problems with current solutions:

  • placing views over other views can (in my experience with UICollectionView and other crap) trigger autorun. Auto power off is bad. Autolayout causes the machine to spike and may have side effects, other than just computing without any reason, other than burning the processor and battery. Thus, you do not want to indicate the reasons for auto-shutdown, for example, adding a subtitle to a view that really really cares about keeping itself in a good location.

  • your view does not necessarily cover the entire screen, so if you want to burn the whole screen, you better use UIWindow ... this should isolate from any view controllers that are touchy added subviews

This is my implementation, category in UIView. I have included methods to take a screenshot before the window blinks, and then save it to the camera frame. Note that UIWindow seems to want to make its own animations when added, will usually disappear in more than a third of a second. Maybe the best way to tell him not to do this.

 // stupid blocks typedef void (^QCompletion)(BOOL complete); @interface UIView (QViewAnimation) + (UIImage *)screenshot; // whole screen + (void)flashScreen:(QCompletion)complete; - (UIImage *)snapshot; // this view only - (void)takeScreenshotAndFlashScreen; @end @implementation UIView (QViewAnimation) + (UIImage *)screenshot; { NSArray *windows = [[UIApplication sharedApplication] windows]; UIWindow *window = nil; if (windows.count) { window = windows[0]; return [window snapshot]; } else { NSLog(@"Screenshot failed."); return nil; } } - (UIImage *)snapshot; { UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } + (void)flashScreen:(QCompletion)complete; { UIScreen *screen = [UIScreen mainScreen]; CGRect bounds = screen.bounds; UIWindow * flash = [[UIWindow alloc] initWithFrame:bounds]; flash.alpha = 1; flash.backgroundColor = [UIColor whiteColor]; [UIView setAnimationsEnabled:NO]; [flash makeKeyAndVisible]; [UIView setAnimationsEnabled:YES]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseOut animations:^{ flash.alpha = 0; } completion: ^(BOOL finished) { flash.hidden = YES; [flash autorelease]; if (complete) { complete(YES); } }]; } - (void)takeScreenshotAndFlashScreen; { UIImage *image = [UIView screenshot]; [UIView flashScreen:^(BOOL complete){ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^{ UIImageWriteToSavedPhotosAlbum(image,self,@selector(imageDidFinishSaving:withError:context:),nil); }); }]; } - (void)imageDidFinishSaving:(UIImage *)image withError:(NSError *)error context:(void *)context; { dispatch_async(dispatch_get_main_queue(),^{ // send an alert that the image saved }); } @end 
0
source share

All Articles