我是Objective-C的新手,刚从头开始制作我的第一个应用程序。这是一个拼写应用程序,如果用户输入错误的字母,当您截取屏幕截图时,我想显示屏幕上显示的相同白色闪光。我该怎么做?
答案 0 :(得分: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]; } ];
答案 1 :(得分:1)
一种简单的方法是在当前视图(或UIView
)上将alpha设置为0的白色UIWindow
。然后,应用可能是这样的闪光效果:
-(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){}];
}
答案 2 :(得分:1)
在所有内容之上添加全屏白色UIView
并为其制作动画。
// 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];
}];