我遇到一个问题,当我点击我的按钮时,淡入淡出的动画无法正常显示淡入和淡出我的视图,视图会再次出现。
View在xib文件中设置为alpha值为" 0"
我的代码:
-(IBAction)startFade:(UIButton*)sender{
UIView *searchView = [UIView safe_cast:[self.view viewWithName:@"searchField"]];
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
[searchView setAlpha:0.f];
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
[searchView setAlpha:1.f];
} completion:nil];
}];
}
答案 0 :(得分:1)
第二个动画在第一个动画的完成处理程序中,所以每次都会做两个动画,你需要将第二个动画分开
尝试这样的事情
-(IBAction)startFade:(UIButton*)sender{
UIView *searchView = [UIView safe_cast:[self.view viewWithName:@"searchField"]];
//assuming searchView.alpha == 1 or 0 by default
CGFloat alpha = searchView.alpha;
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
[searchView setAlpha:1.0f - alpha];
} completion:nil];
}
这应该按每个按钮将其交换为隐藏或可见