How to delay between 2 animations? - ios

I am dismissing one modal view controller and then immediately presenting another modal view controller however I cannot currently use animation on both of them only the second one.
Is there anyway to delay the process so that the user experiences both animations?
The code below currently works however user only sees the second animation obviously:
// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:detailViewController animated:YES];
//Dismiss first one
[self dismissModalViewControllerAnimated:NO];
//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];

There is now a completetion block available in present modal view controller. See this LINK. This is available in iOS5.0 +.
This has the advantage that you don't need to estimate the timer delay if you were to use a timer solution.
Just put the code for your second animation in the block:
//Block safe reference to self to prevent retain cycles
__block typeof (self) selfReference = self;
// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:detailViewController animated:YES completion:
^{
//Dismiss first one
[selfReference dismissModalViewControllerAnimated:NO];
//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[selfReference presentModalViewController:navController animated:YES];
}];

Make a selector that does the following:
- (void)showSecondModalVC {
//Dismiss first one
[self dismissModalViewControllerAnimated:NO];
//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
}
An then in the main piece of code:
// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:detailViewController animated:YES];
[self performSelector:#selector(showSecondModalVC)
withObject:nil
afterDelay:0.5f];
You will have to look closely and see how much it takes for the first modal to show so the animations look good.

You can do it in some other style.
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:detailViewController animated:YES];
[self dismissModalViewControllerAnimated:NO];
[self performSelector:#selector(someFunction) withObject:nil afterDelay:1.0];
- (void) someFunction{
//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
}

Try with this:
// First one configure
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen;
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:detailViewController animated:YES];
//Dismiss first one
[self dismissModalViewControllerAnimated:NO];
NSTimer Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(openSecondView) userInfo:nil repeats:NO];
-(void)openSecondView
{
//Immediately configure and show second one
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
}
Happy Coding...

Related

UIPopoverController is not presenting on "presentViewController"

I am developing iPad application. In this application i am showing ViewController in presentViewController using this following code
[self presentViewController:vc animated:YES completion:nil];
After that i am showing popup using UIPopoverController in that presentviewController with out dismissing "vc". so that i am getting the issue following issue Warning: Attempt to present <SelectionListViewController: 0x7b439960> on <ViewController: 0x7a341e00> which is already presenting (null)
So that the popup is not presenting on ViewController. how to solve this issue. This is existing project now i need to fix this issue.
Thanks in Advance
Present in this manner...
vc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popController = [vc popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionAny;
popController.sourceView = self.view;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:vc animated:YES completion:nil];
}];
I think presentViewController in a performSelector call will solve your problem.
Try this 2 Methods
-(void) present
{
[self performSelector: #selector(ShowSelectionListViewController) withObject: nil afterDelay: 0];
}
-(void) ShowSelectionListViewController
{
[self presentViewController:SelectionListViewController animated: true completion: nil];
}
You should try this one. it worked for me...
if([AppDelegate isIOS8])
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),
^{[self.popover presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];});
}
else
{
[self.popover presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES ];
}

Fix Warning: Attempt to present ViewController on NavigationController whose view is not in the window hierarchy

Currently, I have set up a log-in view for users of my app. Below is the code that presents this log-in view to the user:
// Handle how we present the view
if (self.notificationToProcess != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWNotificationsViewController *viewController = [[NotificationsViewController alloc] init];
viewController.initialDataID = self.notificationToProcess[#"Data"];
self.notificationToProcess = nil;
[self.navigationController pushViewController:viewController animated:YES];
}];
} else if (self.detailURL != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
WebViewController *wvc = [[WebViewController alloc] init];
wvc.URL = self.detailURL;
wvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:wvc animated:YES completion:nil];
self.detailURL = nil;
}];
} else {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
What I'm attempting to do now is display a web-view first if the user has just updated the app. Below is what this new code looks like:
// Handle how we present the view.
if (self.notificationToProcess != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWNotificationsViewController *viewController = [[SWNotificationsViewController alloc] init];
viewController.initialDataID = self.notificationToProcess[#"Data"];
self.notificationToProcess = nil;
[self.navigationController pushViewController:viewController animated:YES];
}];
} else if (self.detailURL != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWWebViewController *wvc = [[SWWebViewController alloc] init];
wvc.URL = self.detailURL;
wvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:wvc animated:YES completion:nil];
self.detailURL = nil;
}];
else if (![versionOfLastRun isEqual:currentVersion])
{
SWWebViewController *webViewController = [[SWWebViewController alloc] init];
NSString *url=#"http://someurl";
webViewController.URL = url;
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:webViewController animated:YES completion:nil];
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:#"VersionOfLastRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else if (versionOfLastRun == nil){
// First start after installing the app
}
else {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
However, when I run the app, the web view is not displayed, I get a warning of:
Warning: Attempt to present ViewController on NavigationController whose view is not in the window hierarchy!
Can anyone help me diagnose the problem? Thank you!
Seems like your viewController is not in Navigation controller hierarchy. This means that your controller is not connected with navigation controller stack which should handle presented controllers.
The other thing that should help is setting your root view controller as follows:
self.window.rootViewController = self.ViewController;
EDIT: since you mention that you don't use storyboards, setting rootViewController should do the trick.
Try to set the window's rootViewController to the navigation controller after you initialize the navigation controller:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navController;
This is how I'm doing it without storyboards.
The problem was that I didn't call self.navigationController dismissViewControllerAnimated:YES completion:^
After correcting this (see listing below), my WebView was shown as expected.
else if (![versionOfLastRun isEqual:currentVersion])
{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWWebViewController *webViewController = [[SWWebViewController alloc] init];
NSLog(#"%#", self.window.rootViewController);
NSString *url=#"http://devstatwatch.drbsystems.com/releases_mobile.php";
webViewController.URL = url;
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:webViewController animated:YES completion:nil];
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:#"VersionOfLastRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}];
}

GKGameCenterViewController wont dismiss?

I dont get it please help i DONT get a log when i hit done
- (IBAction)loadScores:(id)sender {
GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init];
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
// gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
-(void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController {
NSLog(#"rfffff");
[self dismissViewControllerAnimated:YES completion:nil];
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
You have commented the delegates of the GKGameCenterViewController. This means all the delegate methods will not be called like the one that dismisses the view controller. So I suggest you uncomment this line and then run the code and see.

EKEventview controller not showing navigation bar

I used the following code to view the event. But navigation bar doesn't visible.
EKEventViewController *addController = [[EKEventViewController alloc] initWithNibName:nil bundle:nil];
addController.event = self.event;
addController.allowsEditing = YES;
addController.allowsCalendarPreview = YES;
[self.navigationController presentViewController:addController animated:YES completion:nil];
with Present viewcontroller you need to Add sepreated NavigationController for UIViewcontroller like:-
EKEventViewController *addController = [[EKEventViewController alloc] initWithNibName:#"EKEventViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:addController];
addController.event = self.event;
addController.allowsEditing = YES;
addController.allowsCalendarPreview = YES;
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)])
{
[self presentViewController:navController animated:YES completion:nil];
}
else
{
[self presentModalViewController:navController animated:YES];
}

Problems presenting a second modal view controller

At the moment my error says my view controller is already presenting null. I think i have the right idea with my below code, but I'm not implementing it correctly. Thanks for your help
-(IBAction)datePicker
{
//UIViewController *presenter = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^{
/*
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard.storyboard"
bundle:nil];
UIViewController* dateView = [sb instantiateViewControllerWithIdentifier:#"DatePickerViewController"];
*/
[self performSegueWithIdentifier:#"dueDateSegue" sender:self];
//[presenter presentViewController:dateView animated:YES completion:nil];
/*
[self presentViewController:dateView animated:YES completion:^{
UIBarButtonItem *saveDate = [[UIBarButtonItem alloc]
initWithTitle:#"Save Date"
style:UIBarButtonItemStyleDone
target:self
action:#selector(labelDatePicker)];
self.navigationItem.rightBarButtonItem = saveDate;
pick = [[UIDatePicker alloc] init];
[pick setFrame:CGRectMake(0,200,320,120)];
//[pick addTarget:self action:#selector(done) forControlEvents:UIControlEventValueChanged];
//dateFieldText.delegate = self;
//dateFieldText.inputView = pick;
}];
*/
}];
}
In the method datePicker add the following line as the first line of code:
UIViewController *presenter = self.presentingViewController;
And then instead of :
[self presentViewController:dateView animated:YES completion:nil];
try using:
[presenter presentViewController:dateView animated:YES completion:nil];

Resources