将"screenshot flash"显示为对用户的反馈



我对Objective-C很陌生,刚刚从头开始制作了我的第一个应用程序。这是一个拼写应用程序,如果用户输入错误的字母,我想显示屏幕上显示的相同白色闪烁,当您截屏时。我该怎么做?

// 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];     }     ];

在所有内容之上添加一个全屏白色UIView,并为其 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];
}];

一种简单的方法是在当前视图(或 UIWindow)上设置一个 alpha 设置为 0 的白色UIView。然后,应用如下所示的闪光效果:

-(void)flashEffect {
   // Show it suddenly
   [self.flashSubview setAlpha:1.0];
   // Fade it out
   [UIView animateWithDuration:0.5 
                    animations:^{
                       [self.flashSubview setAlpha:0.0];
                    }
                    completion:^(BOOL finished){}];
}

最新更新