如何使iPhone屏幕变暗 [英] How to make iPhone screen dim
问题描述
我的iPhone屏幕上有一个刷新按钮,刷新当前视图中的表格。
I have a refresh button on my iphone screen that refreshes a table in the current view.
屏幕刷新得很漂亮,但有一种方法,屏幕变暗,然后在表刷新后再次点亮?
The screen refresh beautifully, but is there a way I can make the screen dim and then lighten again after the table has refreshed?
推荐答案
您可以在想要调暗的视图上放置一个黑色背景的不透明视图。这将默认的alpha值为0,因此是透明的。然后,您可以使用UIView动画将黑色视图alpha从0设置为0.5(假设),然后返回。
You could place a non-opaque view with a black background over the view you wish to dim. This would have an alpha value of 0 by default and thus be transparent. You could then use a UIView animation to set the black views alpha from 0 to 0.5 (say) and then back.
注意: 以下代码尚未经过测试,但我已使用类似的代码实现相同的效果。
Note: The code below has not been tested but I have used similar to achieve the same effect.
...
dimView.alpha = 0.0f;
[UIView beginAnimations@"fade" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationRepeatAutoreverses:YES];
dimView.alpha = 0.5f;
[UIView commitAnimations];
...
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
dimView.alpha = 0.0f;
}
这篇关于如何使iPhone屏幕变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!