【发布时间】:2011-07-12 09:19:59
【问题描述】:
找了很久,只好放弃问了。
是否可以闪屏(就像使用home键+电源键截屏一样)?
如果是,那么如何?
提前感谢您的回答。
【问题讨论】:
找了很久,只好放弃问了。
是否可以闪屏(就像使用home键+电源键截屏一样)?
如果是,那么如何?
提前感谢您的回答。
【问题讨论】:
将白色全屏 UIView 添加到窗口并为其 alpha 设置动画(播放持续时间和动画曲线以获得您想要的结果):
-(void) flashScreen {
UIWindow* wnd = [UIApplication sharedApplication].keyWindow;
UIView* v = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, wnd.frame.size.width, wnd.frame.size.height)] autorelease];
[wnd addSubview: v];
v.backgroundColor = [UIColor whiteColor];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration: 1.0];
v.alpha = 0.0f;
[UIView commitAnimations];
}
编辑:不要忘记在动画结束后删除该视图
【讨论】:
类似于 Max 提供的答案,但使用 UIView animateWithDuration 代替
- (void)flashScreen {
// Make a white view for the flash
UIView *whiteView = [[UIView alloc] initWithFrame:self.view.frame];
whiteView.backgroundColor = [UIColor whiteColor];
whiteView.alpha = 1.0; // Optional, default is 1.0
// Add the view
[self.view addSubview:whiteView];
// Animate the flash
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut // Seems to give a good effect. Other options exist
animations:^{
// Animate alpha
whiteView.alpha = 0.0;
}
completion:^(BOOL finished) {
// Remove the view when the animation is done
[whiteView removeFromSuperview];
}];
}
animateWithDuration 有不同的版本,例如,如果您不需要延迟并且可以使用默认动画选项,您也可以使用这个较短的版本。
[UIView animateWithDuration:1.0
animations:^{
// Animate alpha
whiteView.alpha = 0.0;
}
completion:^(BOOL finished) {
// Remove the view when the animation is done
[whiteView removeFromSuperview];
}];
【讨论】: