延迟显示子视图
问题描述:
执行此操作时,它直接显示secondviewcontroller,我想要的是viewcontroller首先显示,40或50秒后显示secondviewcontroller,等等。延迟显示子视图
- (void)displayviewsAction:(id)sender
{
PageOneViewController *viewController = [[PageOneViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:secondController.view];
[self.view bringSubviewToFront:viewController.view];
[self.view addSubview:toolbar];
[self.view sendSubviewToBack:viewController.view];
[self.view addSubview:toolbar];
}
任何人有任何想法,我可以做到这一点。
答
可以在一个单独的方法中添加secondViewController和呼叫使用 performSelector:withObject:afterDelay
- (void)displayviewsAction:(id)sender {
PageOneViewController *viewController = [[PageOneViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self performSelector:@selector(secondViewController) withObject:nil afterDelay:40];
}
-(void)secondViewController {
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view];
}
答
的替代/除了由Aravindhanarviless详述的方法是使用一个NSTimer该方法:
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:40 target:self selector:@selector(showSecondViewController) userInfo:nil repeats:NO];
答
尝试使视图看不见,然后在40秒后迅速消失。
secondController.view.alpha = 0.0;
[self.view addSubview:secondController.view];
[UIView animateWithDuration:0.5
delay:40
options:UIViewAnimationCurveEaseInOut
animations:^{
secondController.view.alpha = 1.0;
}
completion:NULL
];