0

我必须尝试在主视图上以编程方式添加一个从 0 不透明度到完全不透明度进行动画处理的按钮。这将是什么编码?我得到了这个编码,但似乎无法让它工作。

[UIElement setAlpha: 0.0f]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5];

[UIElement setAlpha: 1.0f]; 

[UIView commitAnimations]; 
4

1 回答 1

1

将此代码放入您的 viewDidLoad 方法中:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0,0,100,50);
btn.alpha = 0;
[self.view addSubview:btn];

[UIView animateWithDuration: 0.3
                 animations: ^(void) { btn.alpha = 1; } ];
于 2012-11-09T16:22:03.893 回答