4

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

4

3 回答 3

6
// 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];     }     ];
于 2012-10-10T13:07:05.597 回答
2

在所有内容上添加全屏白色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];
}];
于 2012-10-10T12:45:07.253 回答
1

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

-(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){}];
}
于 2012-10-10T12:44:21.067 回答