目前我正在创建一个应用程序,当你第一次启动它时,有一些简介文本和2个按钮。 1按钮跳过教程,另一个按钮执行教程。我希望这些2个按钮和那些标签在一定时间之后出现并且带有淡入动画。谁能给我一些代码示例?我已经尝试过搜索,但结果对我没有帮助。
我更新了一些代码。现在看起来像这样:
.h文件:
@interface startViewController : UIViewController {
IBOutlet UIButton *notourb;
IBOutlet UIButton *tourb;
IBOutlet UILabel *welcomeLabel;
}
- (void)shownotourb;
- (void)showtourb;
- (void)showwLabel;
.m文件(我只会显示按钮中的代码,因为我想出了如何以另一种方式处理标签):
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:@selector(shownotourb) withObject:nil afterDelay:2.0];
[self performSelector:@selector(showtourb) withObject:nil afterDelay:2.5];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shownotourb {
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:notourb];
}
completion:^(BOOL finished){}];
}
- (void)showtourb {
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:tourb];
}
completion:^(BOOL finished){}];
}
答案 0 :(得分:0)
创建一个方法,将按钮添加到视图中,并使用performSelector:afterDelay
方法添加它们,如下所示:
在viewDidLoad
:
[self performSelector:@selector(addButtonsToView) withObject:nil afterDelay:5.0];
并添加此方法以添加按钮:
-(void)addButtonsToView
{
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:button1];
[self.view addSubview:button2];
}
completion:^(BOOL finished){}];
}
希望它有所帮助:)