How to disable swipe gesture of UINavigation Controller - ios

In App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WalkThrough *viewControllers=[[WalkThrough alloc]init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewControllers];
[self.window setRootViewController:self.navigationController];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
navigationController.navigationBar.hidden = YES;
self.window.backgroundColor = [UIColor clearColor];
[self.window makeKeyAndVisible];
return YES;
}

Try to disable interactivePopGestureRecognizer after [window makeKeyAndVisible].
The key to the problem is that interactivePopGestureRecognizer property is nil until both two conditions are met:
the navigationController is associated to the window
the window become key and visible

Related

LeftSideMenu in MFSideMenu not responding

I'm implementing MFSideMenu in my project and this is my AppDelegate Code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil]
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
The menu appear correctly and all of it's contents but the components inside it (button, tableview, etc...) not responding to any interaction . I've created a new clean project and add the menu only on it but with no hope.
Thanks in advance
you can try like this
SideViewController *leftMenuVC = [[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[UINavigationController alloc]initWithRootViewController:leftMenuVC] rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;

How to programmatically create UIView so that it does not overlap the status bar

I am using the following code in my app delegate to programmatically create the application's window and root controller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
self.window.rootViewController.view = [[UIView alloc] init];
self.window.rootViewController.view.backgroundColor = [UIColor redColor];
return TRUE;
}
The code works fine, however the view associated to the root view controller overlaps the status bar, which I would like to avoid (see picture below).
How should I proceed? In particular I want to have a lightgray background for the status bar (similar to the apps created with a storyboard) and also handle orientation change correctly.
Thanks
Well, you can do something as following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
self.window.rootViewController.view.backgroundColor = [UIColor whiteColor];
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0,
[UIApplication sharedApplication].statusBarFrame.size.height,
[UIScreen mainScreen].bounds.size.width,
[UIScreen mainScreen].bounds.size.height)];
redView.backgroundColor = [UIColor redColor];
[self.window.rootViewController.view addSubview:redView];
[self.window makeKeyAndVisible];
return TRUE;
}
should look like this:

Customize View Controller Stack on didFinishLaunching

I am trying to present a tutorial/login/introduction view controller for my app on first launch using the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIViewController *firstController = [[UIViewController alloc] init];
[self.window setRootViewController:firstController];
if ([self shouldShowIntro]) {
IntroViewController *introViewController = [[IntroViewController alloc] init];
[firstController presentViewController:introViewController animated:NO completion:nil];
}
return YES;
}
This works fine, but there is an annoying visual effect that takes place... Before you see the IntroViewController, there is a split second where the firstController is visible. I tried presenting the IntroViewController before setting the rootViewController of the window, but this (not surprisingly) results in the following warning:
Warning: Attempt to present <IntroViewController: 0x7fd8eb3362f0> on <UIViewController: 0x7fd8eb335180> whose view is not in the window hierarchy!
How can I modally present the IntroViewController without this annoying visual flash? I want IntroViewController to already be showing after the launch screen disappears and be able to be dismissed modally.
The following works for me with no flicker running on iOS 8.1 on an iPhone 6 and in the simulator. I used SDK version 8.1 and I think your SDK level is different because I got different warnings and results than you using your provided code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIViewController *firstController = [[UIViewController alloc] init];
firstController.view.backgroundColor = [UIColor blueColor];
[self.window setRootViewController:firstController];
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController* modalViewController = [[UIViewController alloc] init];
modalViewController.view.backgroundColor = [UIColor grayColor];
[firstController presentViewController: modalViewController animated: NO completion: nil];
});
// dismiss after a few seconds..
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[firstController dismissViewControllerAnimated: YES completion: nil];
});
return YES;
}
Update with MMDrawerController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
MMDrawerController *drawerController = [[MMDrawerController alloc] init];
drawerController.centerViewController = [[UIViewController alloc] init];
drawerController.centerViewController.view.backgroundColor = [UIColor blueColor];
drawerController.rightDrawerViewController = [[UIViewController alloc] init];
drawerController.rightDrawerViewController.view.backgroundColor = [UIColor greenColor];
drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
drawerController.closeDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
[self.window setRootViewController:drawerController];
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController* modalViewController = [[UIViewController alloc] init];
modalViewController.view.backgroundColor = [UIColor grayColor];
[drawerController presentViewController: modalViewController animated: NO completion: nil];
});
// dismiss after a few seconds..
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[drawerController dismissViewControllerAnimated: YES completion: nil];
});
return YES;
}
Also, per you comment it sounds as if having the pre-loaded view is key. Try invoking [firstController view] and [modalController view] before you present to ensure they're loaded.
try moving this line below the code where you set your view controllers.
[self.window makeKeyAndVisible];
something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController *firstController = [[UIViewController alloc] init];
[self.window setRootViewController:firstController];
if ([self shouldShowIntro]) {
IntroViewController *introViewController = [[IntroViewController alloc] init];
[firstController presentViewController:introViewController animated:NO completion:nil];
}
[self.window makeKeyAndVisible];
return YES
}
Put
if ([self shouldShowIntro]) {
IntroViewController *introViewController = [[IntroViewController alloc] init];
[firstController presentViewController:introViewController animated:NO completion:nil];
}
in to the viewDidAppear function of FirstViewController rather than in the AppDelegate. That should suppress the warning and perform the operation smoothly.

Changes made to Navigation Controller are not shown

I copied the example from View Controller Catalog for iOS made some changes to the colour and expected to see them reflected on the simulator. Nothing happens ???
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[navigationController setNavigationBarHidden:NO animated:YES];
navigationController.title = #"Hello";
navigationController.navigationBar.barStyle = UIBarStyleBlack ;
navigationController.navigationBar.translucent = NO;
navigationController.navigationBar.tintColor = [UIColor blackColor];
navigationController.navigationBar.barTintColor = [UIColor greenColor];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = navigationController;
[window makeKeyAndVisible];
return YES; }
What do I do wrong?
Several things: First: be sure than in the General information of your target app, in Main Interface field is blank. (If you donĀ“t find it, delete all *.storyboard files that you have).
Second: In your AppDelegate.h should be this property:
#property (strong, nonatomic) UIWindow *window;
And last: Change this in your code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
In order to know changes is better step by step. (.title is in ViewController).

UINavigationBar becomes transparent after switching views in uitabbar

In the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, I initialized an instance of UINavigationController with GeneralOptionsTableViewController and an instance of GeneralOptionsMapViewController. The navigationBar color was set to green. However, when I switch between the UINavigationController with GeneralOptionsTableViewController and GeneralOptionsMapViewController, the navigationBar becomes transparent. I tried resetting the navigationbar color in the viewWillAppear method but it does not seem to work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
GeneralObjectTableViewController *generalObjectTableViewController = [[GeneralObjectTableViewController alloc] init];
GeneralObjectMapViewController *generalObjectMapViewController = [[GeneralObjectMapViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:generalObjectTableViewController];
navigationController.navigationBar.barTintColor = [UIColor greenColor];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:navigationController, generalObjectMapViewController, nil]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

Resources