presentViewController in AppDelegate with delay in iOS8 - ios8

So I had a full working solution in iOS7 that displays a LoginViewController via presentViewController in the AppDelegate's didFinishLaunching.
Basically I am doing something like this:
UIViewController *backgroundViewController = ...
self.window.rootViewController = backgroundViewController;
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:loginViewController
animated:NO ...]
In iOS8 I see a jump. First I see the backgroundViewController then after about 1 second or so the login appears.
So, how can I prevent this jump in iOS8?
I am seeing that are a ton of developers with this kind of problem but still didn't find a solution.

Also a hack (for now), but just one line of code
Add the view of the view controller you're presenting to the window before presentation
UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view setBackgroundColor:[UIColor greenColor]];
// Temporary iOS8 fix for 'presentation lag' on launch
[self.window addSubview:viewController.view];
[self.window.rootViewController presentViewController:viewController animated:NO completion:nil];
If you are presenting a navigation controller than add the navigation controller's view instead of its top view controller.

I have a quick hacky fix:
//Make a screenshot of the ViewController first, or use a real image if you want
__block UIImageView *fakeImageView = [[UIImageView alloc] initWithImage:image];
fakeImageView.frame = vc.view.frame;
[self.view addSubview:fakeImageView];
[self presentViewController:vc animated:animated completion:^{
[fakeImageView removeFromSuperview];
fakeImageView = nil;
}];
It is not good for long term, but can quickly fix this issue without changing too much code.
Waiting for better solutions.

You can set the window to an instance of a temporary controller.
self.window.backgroundColor = [UIColor whiteColor]; //do some styling etc.
self.window.rootViewController = [LoginViewController new];
[self.window makeKeyAndVisible];
From the set controller (LoginViewController) you can push your real login controller with the desired transition. Once the login sequence is over you can make a transition from the login controller to the default application root view controller.
[UIView transitionWithView:[AppGlobal sharedApp].applicationWindow
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[AppGlobal sharedApp].applicationWindow.rootViewController = [AppRootViewController new];
} completion:nil];

I have also faced the same problem in iOS8 and I found this solution:
ABCViewController *obj = [[ABCViewController alloc] initWithNibName:#"ABCViewController" bundle:nil];
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
[self.navigationControler.view.layer addAnimation:transition forKey:nil];
[appDelegate.navigationControler obj animated:NO];
obj = nil;
I hope this solution can help you!

This should work:
call [loginViewController view]
Before presenting it.

Related

Main storyboard setting affect rotation function in iOS8

In my app, the rotation works fine in iOS7 but not working in iOS8.
As you can see, the status bar rotates, but the view controller does not.
I found the issue is caused by main storyboard setting, but I have no idea why it cased the issue. I just removed main storyboard setting in project file and everything works fine in iOS8.
Following is my codes to load storyboard.
[self setMainStoryboard:[UIStoryboard storyboardWithName:#"MainStoryboard-ipad" bundle:nil]];
UIViewController *vc = [mainStoryboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[self.window setRootViewController:vc];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
Maybe I used the wrong way to load storyboard?
I fix the problem, but I think this might not be a good solution. It's just a workaround. Anyway, here is what I have done. If you run into the same problem, you can try removing main storyboard setting in your target.
That's it, no further steps. Everything is fine after I remove main storyboard setting. Maybe the way I load main storyboard is incorrect or there is something wrong with my setting of storyboard.
Following is the codes I used to load storyboard:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateInitialViewController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
// Override point for customization after application launch.
[self.window setRootViewController:nav];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
If anyone know the correct way to use main storyboard, please give me some feedback. Thanks!

Activity Indicator will not go away

I am using the following code to show an Activity Indicator while some data is loading. The problem is that when I try to hide it again. The Activity Indicator stays put. The screen lightens a bit but that is it.
To show it:
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
[self.tableView addSubview:self.overlayView];
To hide it:
[self.activityIndicator stopAnimating];
[self.overlayView removeFromSuperview];
Try to add your overlayView to the superview of your tableView :
[self.view.superview addSubview:self.overlayView];
I figured it out with a combination of stackoverflow questions. Here is my code to show the UIActivityIndicatorView
-(void)loadView {
[super loadView];
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.tableView addSubview:self.overlayView];
[self.activityIndicator startAnimating];
}
Here is the code to hide it. It looks like putting the code in the loadView event made all the difference.
[overlayView removeFromSuperview];

presentViewController makes black screen Xcode 5.1.1

Hello you lovely reader,
I've been stuck on this for 2 days now so I really hope somebody could help me get this fixed. I get a blackscreen when switching views with Xcode 5.1.1. I saw this problem on stackoverflow but no post helped me.
I want to switch to view Connexion from view Inscription and be able to switch back to view Inscription from view Connexion.
I do it with animation, here is the code from InscriptionViewController.m :
- (IBAction)swipeGestureToRight:(UISwipeGestureRecognizer *)sender { // Switch à la vue de connexion
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
ConnexionViewController *vc = [[ConnexionViewController alloc] init];
UIView *newView = vc.view;
// remove the current view and replace with myView1
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"SwitchView"];
}
And here is the code from ConnexionViewController :
- (IBAction)swipeGestureToLeft:(UISwipeGestureRecognizer *)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
What do you guys think ? Where can it come from ?
Thanks in advance for your time and help.
:)
PS : I tried to remove all of this and replace by
ConnexionViewController *vc = [[ConnexionViewController alloc] init];
[self presentViewController:vc animated:NO completion:nil];
And I still get a black screen.
EDIT : Problem Solved. Thx for your help. After 2 days I found out.
Here is the solution :
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ConnexionViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"ConnexionViewController"];
UIView *newView = vc.view;
// remove the current view and replace with myView1
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"SwitchView"];
Hey I faced same in xcode 5.1.1
Instead of presentViewController, I faced while pushViewController
Problem is xcode not able to automatically pick controller.xib file in my case, so I added xib name
Initially-
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
After-
self = [super initWithNibName:#"UserConversationViewController" bundle:nibBundleOrNil];
It solves my problem, hope it will also solve someone's problem. :)

Resize the UIViewController View

I am new in iPhone/Ipad Application development and Just learning the UIViewController, UIView etc with Xcode and while using uiviewcontroller want to resize but my tricks logic are not working. please let me know if you have any Idea with this.
Thanks
i think your are looking like this.
(IBAction)buttonPressed:(id)sender
{
menuView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bgground.jpg"]];// i used 1 view name is menuView
UIViewController *menu =[[UIViewController alloc] init];menu.view = menuView;
[menu setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:menu animated:YES];
[menu release];
}
After resize try this code
UIViewController* view = [[UIViewController alloc] init];
[self presentModalViewController: view animated: NO];
[self dismissModalViewControllerAnimated: NO];
[view release];

Make AppDelegate's Navigation Controller accessible from DetailViewController of SplitView

My DetailView of a SplitView has a Map with Annotations. Upon clicking an Annotation the entire window (and not just the DetailView) should go to another view. Unfortunately that doesn't work.
This is how I'm creating my NavigationController in my AppDelegate
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navigationController.view];
This is how I'm creating the SplitView
left = [[MapSplitViewLeft alloc] initWithStyle:UITableViewStylePlain];
right = [[MapViewController alloc] init];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:left,right, nil];
self.view = splitViewController.view;
left.right = right;
[left release];
[right release];
And that's what's being called when clicked on an Annotation:
- (void)showDetails:(id)sender {
NSLog(#"Yes it works");
VenueViewController *vviewcontroller = [[VenueViewController alloc]
initWithNibName:#"VenueViewController" bundle:[NSBundle mainBundle]];
AppDelegate *del = (AppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:vviewcontroller animated:YES];
}
When I click on the Annotation I only get "Yes it works" but nothing else is happening.
Thanks so much for any advise.
Every UIViewController has the property "navigationController". Try with your current ViewController to push the new Viewcontroller.
[self.navigationController pushViewController:vviewcontroller animated:YES];
edit: Sorry, you mean the entire window! I think that would not work.
edit2: Maybe this answer can help you how to add a view over window in uiviewcontroller But i think thats that view is not on your navigationController-Stack

Resources