我怎么能强迫的iOS立即改变背景颜色? [英] How can I force iOS to change background color immediately?

查看:124
本文介绍了我怎么能强迫的iOS立即改变背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法来改变窗口的背景颜色立刻?

Is there any way to change the background color of a window immediately?

我需要一个闪烁背景,即,红色/绿色中的第二的间隔闪烁。依我之见,背景颜色不会立即改变,但左侧功能时才会出现。

I need a blinking background, i.e. red/green blinking in an interval of a second. As i see, the background color will not change immediately, but only when function is left.

有没有办法强制系统进行更改,并立即重绘窗口的背景是什么?

Is there any way to force the system to change it and redraw the window's background immediately?

推荐答案

纳文给了一个良好的开端,但您可以通过动画颜色变化显示出多一点的类。

Naveen has given a good first start, but you can show a little more class by animating the colour change.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Set up the initial background colour
    self.view.backgroundColor = [UIColor redColor];

    // Set up a repeating timer.
    // This is a property,
    self.changeBgColourTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeColour) userInfo:nil repeats:YES];
}

- (void) changeColour {
    // Don't just change the colour - give it a little animation. 
    [UIView animateWithDuration:0.25 animations:^{
        // No need to set a flag, just test the current colour.
        if ([self.view.backgroundColor isEqual:[UIColor redColor]]) {
            self.view.backgroundColor = [UIColor greenColor];
        } else {
            self.view.backgroundColor = [UIColor redColor];
        } 
    }];

    // Now we're done with the timer.
    [self.changeBgColourTimer invalidate];
    self.changeBgColourTimer = nil;
}

这篇关于我怎么能强迫的iOS立即改变背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆