Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须尝试在主视图上以编程方式添加一个从 0 不透明度到完全不透明度进行动画处理的按钮。这将是什么编码?我得到了这个编码,但似乎无法让它工作。
[UIElement setAlpha: 0.0f]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIElement setAlpha: 1.0f]; [UIView commitAnimations];
将此代码放入您的 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; } ];