我有一个视图,随着应用程序状态的变化,我改变了它的背景。基本上我想让视图背景改变在幻灯片中动画化。我一直在寻找解决办法,但什么也没找到。
所以我想要有一个从当前背景到下一个背景的过渡
//current to:
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
我没有麻烦让背景改变,但我想动画它。
你可以这样做:
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionAutoreverse
animations:^
{
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
}
completion:nil
];
一个非常简单的处理方法:
如yourView.backgroundColor = [UIColor redColor];
然后使用这个动画来改变颜色
#import <QuartzCore/QuartzCore.h>
yourView.backgroundColor = [UIColor blueColor];
CATransition *transiton = [[CATransition alloc] init];
transiton.duration = .5;
[yourView.layer addAnimation:transiton forKey:@"Animation"];
只是一个简单的动画块:
[UIView animateWithDuration:time animations^{
self.view.backgroundColor = [UIColorWithPatternImage:image];
}];
这只是动画传输,占用时间秒。