Cra*_*Dev 7 animation alphablending objective-c ios
我想创建一个更改alpha值的简单动画:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[view1 setAlpha:0.00];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
好的,这样我将alpha值更改为两秒并且它工作正常,但我想要这样的事情:当alpha为0时,动画必须再次开始alpha = 1所以动画应该是:alpha 0 - > alpha 1 - > alpha 0 - > alpha 1 - > ...依此类推,持续时间为2秒.你能帮助我吗?
我的完整代码是
-(IBAction){
FirstViewController *firstViewController = [[[FirstViewController alloc] init]autorelease];
[firstViewController.label1 setAlpha:1.00];
[firstViewController.label2 setAlpha:1.00];
view = firstViewController.viewFirst; //this is my view and I copy in other view
[self fadeOut:nil finished:nil context:nil];}
- (void) fadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ];
[view setAlpha:0.00];
[UIView commitAnimations];
}
- (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:) ];
[view setAlpha:1.00];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
Pie*_*ter 10
在iOS 4及更高版本中,您可以这样做
view1.alpha = 1.0;
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionRepeat|UIViewAnimationAutoReverse
animations:^{
view1.alpha = 0.0;
}
completion:nil
];
Run Code Online (Sandbox Code Playgroud)
- (void) fadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
if(animationRunning){
[UIView setAnimationDidStopSelector:@selector(fadeIn:finished:context:) ];
}
[view1 setAlpha:0.00];
[UIView commitAnimations];
}
- (void) fadeIn:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
if(animationRunning){
[UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:) ];
}
[view1 setAlpha:1.00];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
这些将在动画结束时互相调用......
你需要做的就是打电话:
[self fadeOut:nil finished:nil context:nil];
Run Code Online (Sandbox Code Playgroud)