简体   繁体   English

如何让iPhone屏幕变暗

[英]How to make iPhone screen dim

I have a refresh button on my iphone screen that refreshes a table in the current view. 我的iphone屏幕上有一个刷新按钮,用于刷新当前视图中的表格。

The screen refresh beautifully, but is there a way I can make the screen dim and then lighten again after the table has refreshed? 屏幕刷新很漂亮,但是有一种方法可以使屏幕变暗然后在桌子刷新后再次变亮吗?

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. 默认情况下,它的alpha值为0,因此是透明的。 You could then use a UIView animation to set the black views alpha from 0 to 0.5 (say) and then back. 然后,您可以使用UIView动画将黑色视图alpha设置为0到0.5(比方说)然后再返回。

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

你可以在顶部加载黑色的50%alpha视图,可能会淡入吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM