Nun*_*ter 0 iphone core-animation uibutton ipad ios
我有一组UIButtons和UILabel,我想在选择一个按钮时淡出,这是正确的按钮.
我尝试了很多东西(在代码块中对它们进行了评论),只有UILabels淡出.我在这里错过了什么?
-(IBAction)answerButtonPressed:(UIButton *)sender {
NSLog(@"Game Question Answer Pressed: %i", sender.tag);
NSLog(@"%@", sender.titleLabel.text);
int selectedAnswer =0;
selectedAnswer = [question.answer intValue];
if (selectedAnswer == sender.tag) {
NSLog(@"GameQ %@ is the correct answer", sender.titleLabel.text);
//self.toggleView;
[labelA setAlpha:0];
[labelB setAlpha:0];
[labelC setAlpha:0];
[labelD setAlpha:0];
/*
[buttonA setAlpha:0];
[buttonB setAlpha:0];
[buttonC setAlpha:0];
[buttonD setAlpha:0];
[buttonA setHidden:YES];
[buttonB setHidden:YES];
[buttonC setHidden:YES];
[buttonD setHidden:YES];
*/
[sender setAlpha:1];
[sender setHidden:NO];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];
[UIView setAnimationDelegate:[UIApplication sharedApplication]];
[UIView setAnimationDidStopSelector:@selector(endIgnoringInteractionEvents)];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
我已经清理了方法并只使用了一种类型的动画块.UIButton仍然不会淡出,但标签确实如此.这是我作为动画块的内容:
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{labelA.alpha = 0;}
completion:nil];
Run Code Online (Sandbox Code Playgroud)
我偶然发现了一些事情.您正在组合两种类型的动画技术.新旧:
要么:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
buttonA.alpha = 0;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
或者(因为它是"现代"方式而首选)
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];
Run Code Online (Sandbox Code Playgroud)
正如您所拥有的那样,将这两者组合在一起可能会导致块被多次调用,因为第一个动画技术会插入第二个动画技术.基本上,在队列中放置许多动画,将按钮淡入0非常快.
此外,默认情况下(默认情况下)(默认情况下使用块)用户交互处于禁用状态.无需明确地执行此操作.
| 归档时间: |
|
| 查看次数: |
1999 次 |
| 最近记录: |