在循环中改变视图背景图像

时间:2013-11-10 18:56:31

标签: ios uiview uiviewanimation

我有3张图片用于设置self.view.background。我正在尝试,设置像Twitter iOS APP登录UI的背景(每5秒随机更改一次背景图像。)

所有随机过程都已完成,我真正遇到麻烦的是,当我使用UIAnimation时,它会随机化同步模式。当它工作时,整个UI按预期等待UIAnimation过程。

这是我的代码:(我在viewDidLoad方法的末尾调用此方法:

注意:同样,设置alpha不起作用..

-(void)startBackgroundImageChange
{

    dispatch_async(dispatch_get_main_queue(), ^{

    [UIView animateWithDuration:5.0
                          delay:0.2
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{

                         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

                         self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:[self setBackgroundImage]]];

                         self.view.alpha = 1.0;

                         //here you may add any othe actions, but notice, that ALL of them will do in SINGLE step. so, we setting ONLY xx coordinate to move it horizantly first.
                     }
                     completion:^(BOOL finished){

                         //here any actions, thet must be done AFTER 1st animation is finished. If you whant to loop animations, call your function here.
                         self.view.alpha = 0.3;
                         [self startBackgroundImageChange];
                     }];

        });

}

任何帮助将不胜感激..

0 个答案:

没有答案