Reputation:
I am doing a modal view controller (changeviewcontroller) that will be appeared just 5 seconds , so how to do that ? what are the important codes i need to write?
Upvotes: 0
Views: 219
Reputation: 20541
For MVC(Model View Controller)
-(void)viewWillAppear:(BOOL)animated
{
[self performSelector:@selector(CloseViewController) withObject:nil afterDelay:5.0];
}
-(void)CloseViewController{
[yourViewController dissmissModalViewController];
}
if you use here any view then its also work pretty like bellow
-(void)viewWillAppear:(BOOL)animated
{
[self performSelector:@selector(hideView) withObject:nil afterDelay:5.0];
}
-(void)hideView{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFromBottom];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[yourView layer] addAnimation:animation forKey:@"transitionViewAnimation"];
yourView.hidden=YES;
}
in above i use Imageview Insted of MVC. I hope its useful for you... :)
Upvotes: 0
Reputation: 1742
Try this: create a method in you modalview controller class to dismiss modal view controllr.
-(void)dismissModal{
[self dissmissModalViewController];
}
Call this method with a delay of 5 seconds, from your viewdidLoad method.
-(void)viewDidLoad{
[self performSelector @selector(dismissModal) afterDelay:5.0 ];
}
check the syntax, i am not using xcode .
Upvotes: 0
Reputation: 15213
Use the -performSelector:withObject:afterDelay:
method:
-(void)someButtonClicked:(id)sender
{
[self performSelector:@selector(openController) withObject:nil afterDelay:5.0];
}
-(void)openController
{
//present the view controller
SomeViewController *ctrl = ....;
[self present...];
}
Upvotes: 2
Reputation: 6862
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(theSelector) userInfo:nil repeats:NO];
This should do it. Just insert the right selector.
Upvotes: 0
Reputation: 38249
Do this:
[UIView animateWithDuration:5
animations:^{
//add you modal view here
}];
Upvotes: 0
Reputation: 1916
Look in to the NSTimer class. Set it to run 5 seconds and invoke a selecor to dismiss the view. It's all in the Apple Documentation
Upvotes: 0