ViewDeck sizing of left UIViewController - ios

I am using ViewDeck to power the sliding UI in my iPad app but i'm hitting a few problems.
I want to size the leftViewController to a specific size regardless of the rotation. The code I have to setup ViewDeck is as follows oh and i'm using storyboards.
- (id)initWithCoder:(NSCoder *)aDecoder
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"leftViewController"];
JWTimerGroupsViewController *timerGroupsViewController = navigationController.viewControllers[0];
IISideController *constrainedSizeLeftViewController = [[IISideController alloc] initWithViewController:navigationController];
JWMainTableViewController *middleViewController = (JWMainTableViewController *)[storyboard instantiateViewControllerWithIdentifier:#"middleViewController"];
[timerGroupsViewController setDelegate:middleViewController];
self = [super initWithCenterViewController:middleViewController leftViewController:constrainedSizeLeftViewController];
self.centerhiddenInteractivity = IIViewDeckCenterHiddenNotUserInteractiveWithTapToClose;
/* This below IS NOT the size of the left view controller? Just seems odd that it isn't */
[super setLeftSize:200];
[super setSizeMode:IIViewDeckViewSizeMode];
if (self) {
// Add any extra init code here
}
return self;
}
The setLeftSize appears to set the topViewControllers width? Which then makes the left view controller size inconsistent when rotating.
Also I'm seeing some really terrible blocky shadows when the topVC is opened and then the device is rotated.
Is it possible to fix the size of the left ViewController and the amount the top VC opens in ViewDeck?
EDIT
I have just found a reference to this method:
IISideController *constrainedSizeLeftViewController = [[IISideController alloc] initWithViewController:navigationController constrained:200];
Which DOES constrain the left viewcontroller to a specific value. But now there is still no way to have the top VC open to that width?!

You could try the approach suggested here: https://stackoverflow.com/a/16484446/928209
Basically it is:
instantiate your IIViewDeckController in code (not from the
storyboard)
set the center view of the view deck controller to the
rootViewController from your storyboard and side views to whatever
you need.
set the rootViewController of your app to the view deck
controller.
Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard* storyboard = self.window.rootViewController.storyboard;
UINavigationController* leftSideVC = (UINavigationController*)[storyboard instantiateViewControllerWithIdentifier:#"tableNavController"];
UINavigationController* centerNavVC = (UINavigationController*) self.window.rootViewController;
IIViewDeckController* viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:centerNavVC leftViewController:leftSideVC rightViewController:nil];
self.window.rootViewController = viewDeckController;
viewDeckController.resizesCenterView = YES;
viewDeckController.sizeMode = IIViewDeckViewSizeMode;
[self.window makeKeyAndVisible];
return YES;
}
When I tried this approach coding in my IIViewDeckController after loading my storyboard, I found that a lot of my problems with view sizing went away. Before, for example, in order to make the side view a fixed width I had to set the leftSize property to (screenWidth - width) instead of the actual "width" I wanted. Once I made the IIViewDeckController the rootViewController of the app not via the storyboard but instead in code in my AppDelegate, I could set the fixed size to "width" and it worked properly.

Related

Storyboard view resizing trouble

Full disclaimer- I'm pretty new to iOS. I created a tableview with custom cells using the storyboard with a navigation controller as the initial entry point, and my tableview as the navigation controller's root view. When I run the app in the simulator, it seems as though everything is oversized/zoomed in, though my storyboard looks like this:
I've tried with iPad and iPhone and in both devices my story board doesn't pop up properly. I instantiate my root view controller thus:
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//get a pointer to my main storyboard
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
//instantiate my nav controller + item controller through the storyboard
UINavigationController *nav = [mainStoryBoard instantiateViewControllerWithIdentifier:#"navStoryBoard"];
ItemsViewController *ivs = [mainStoryBoard instantiateViewControllerWithIdentifier:#"tableStoryBoard"];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.window.backgroundColor = [UIColor clearColor];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.
return YES;
}
Why won't my tableView appear in the correct size when I run my app? Am I instantiating my views incorrectly?
From the screenshot it looks like you are using Size classes (which is usually enabled by default). And hence the zoomed or scaled up behaviour.
If you are developing for a particular form factor, you may disable the "Use Size Class" property of the View Controller. More details here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/EnablingAdaptiveSizeDesign.html
However, if you want your UI to be scalable on different form factors - you should keep this checked and use Autolayout constrains for your Table View. More details here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/UnderstandingAutolayout.html

UISplitViewController: Does not show up when setting it up pragmatically

I am trying to setup a splitviewcontroller using storyboards. The code below is what I have so far. However, it is showing a black screen. I have a storyboard name Main. I have two viewcontrollers in the storyboard. I read how to do this from an article, but can't get it to work. I must be missing something small. Any help is appreciated.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
ViewController *firstVC = [sb instantiateViewControllerWithIdentifier:#"ViewController"];
ViewController1 *secondVC = [sb instantiateViewControllerWithIdentifier:#"ViewController1"];
CGRect frameFirstVC = firstVC.view.frame;
frameFirstVC.size.width = 100;
CGRect frameSecondVC = secondVC.view.frame;
frameSecondVC.size.width = 100;
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
[self.window addSubview:splitVC.view];
[self.window makeKeyAndVisible];
return YES; }
You shouldn't add the split view controller's view as a subview of your window directly. Instead, set the window's rootViewController property:
self.window.rootViewController = splitVC;
In addition to configuring the view hierarchy, this sets up additional state and layout information for the app to properly display and use the split view controller.
(I should point out that instead of writing any of this code, you could put the split view controller in your storyboard, mark it the initial view controller, then use that storyboard as your app's main interface file. That's a bit of a bigger change, though.)

PrepareforSegue in the initial view control

In Storyboard I have a TabBarController set as the initial view controller which connects ("view controller" relationship) to a Navigation Controller, which in turn connects to a View controller (iphone5VC).
How is it possible to programmatically change the view controller iphone5VC to iphone4VC? I have to decide which of iphone5VC or iphone4VC I will display depending on the phone size (iphone4, 5)
Thanks a lot to both of you. I finally decided to have only one Storyboard and use specific viewcontrollers on an adhoc basis when the 3.5 screen really needs to have a slightly different layout.
What I did is:
Added <UITabBarControllerDelegate> in the viewcontroller .h file from which the user presses on the TabBar to select the view.
Added in the viewdidLoad of the .m file:
UITabBarController *tbc = self.tabBarController;
[tbc setDelegate:self];
and then added in the same file:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
UIStoryboard *myStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
CGSize result = [[UIScreen mainScreen] bounds].size;
if (tabBarController.selectedIndex == 1) // button # 2 pressed
{
if (result.height == IPHONE4_HEIGHT)
{
navController = (UINavigationController *) [myStoryBoard instantiateViewControllerWithIdentifier:#"ViewControlleriphone4"];
[self presentViewController:navController animated:NO completion:nil];
}
else
{
navController = (UINavigationController *) [myStoryBoard instantiateViewControllerWithIdentifier:#"ViewControlleriphone5"];
[self presentViewController:navController animated:NO completion:nil];
}
}
}
If I'm reading your question correctly, you want to include a "check" in your app where the result will set the size of your view controllers, and I'm assuming the layout of the views contained within, based upon which phone the user has. If I have this correct, check out this thread. Also, I would strongly recommend using Auto Layout, which will automatically place the views inside your view controller, regardless of screen size and layout (portrait/landscape).
If I'm not understanding your question, maybe paste a screenshot or some code. Hope this helps, good luck!
So if i am understanding you correctly, you really want to load a separate storyboard (and associated viewController)depending on the device type.
if so, what you need to do is have your main storyboard only contain the initial TabBarController, Navigation Controller, and a subclass of UIViewController we'll call dynamicViewController. The dynamicViewController will load the appropriate storyboard based on the device type. Obviously the various storyboards will need to exist (in the code below, the storyboards are named iphoneV4.storyboard and iphoneV5.storyboards)
So your dynamicViewController, simply needs the following -(void)viewDidLoad method;
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController __unused * targetViewController = nil;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIStoryboard *targetStoryboard = (screenBounds.size.height == 568) ? [UIStoryboard storyboardWithName:#"iphoneV5" bundle:nil] : [UIStoryboard storyboardWithName:#"iphoneV4" bundle:nil];
targetViewController = [targetStoryboard instantiateInitialViewController];
if (self.parentViewController && ![self.parentViewController isKindOfClass:UITabBarController.class] && ![self.parentViewController isKindOfClass:UINavigationController.class]) {
// replace self with the target view controller
[self.parentViewController addChildViewController:targetViewController];
[self.view.superview insertSubview:targetViewController.view aboveSubview:self.view];
[self.view removeFromSuperview];
[self removeFromParentViewController];
} else { // tab bars, nav controllers, and modal dialogs
[self addChildViewController:targetViewController];
CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
targetViewController.view.frame = f;
[self.view addSubview:targetViewController.view];
}
}

Sidemenu with tabBarControllers in Storyboard

Hi Fellow iOS Developers, I am a newbie developing a project with 5 tab Views and on the first and second tabs I have slide out menus using Container views from example code by Michael Frederick on his GitHub page Project Link: https://github.com/mikefrederick/MFSideMenu. He is using a nib (.xib) files though I am using Storyboard to achieve the same and struck with defining the container and child views. can kindly some one advice how to modify the below code to accommodate in my storyboard.
the original code in the AppDelegate.m is
- (DemoViewController *)demoController {
return [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
}
- (UINavigationController *)navigationController {
return [[UINavigationController alloc]
initWithRootViewController:[self demoController]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:[self navigationController],
[self navigationController], nil]];
SideMenuViewController *leftSideMenuController = [[SideMenuViewController alloc] init];
SideMenuViewController *rightSideMenuController = [[SideMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:tabBarController
leftMenuViewController:leftSideMenuController
rightMenuViewController:rightSideMenuController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
#end
how to modify the code to accommodate the container parent view and child views ?
where should i instantiate the code for the parent and child of the 2nd tab view ? in AppDelegate or the View Controller ?
If any other Details are required leave a comment please. Any Help Will be greatly appreciated. thanks in Advance.
I don't know if you still need this, but i had the exactly same problem today, too. What you need to do is:
remove the both methods over your app Delegate
put this in your app Delegate:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD" bundle:[NSBundle mainBundle]];
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"THE_IDENTITY_OF_YOUR_SIDEMENU"];
UITabBarController *centerViewController = [storyboard instantiateViewControllerWithIdentifier:#"IDENTITY_OF_YOUR_TABBARCONTROLLER"];
[container setCenterViewController:centerViewController];
[container setLeftMenuViewController:leftSideMenuViewController]; //for the right Side, its the same way...
[container setPanMode:MFSideMenuPanModeNone]; //remove this line, if you need the pan mode
return YES;
In your Storyboard you have to put a ViewController as a subclass from "MFSideMenuContainerViewController". Mark this View as the "Initial View Controller" in the Attribute Inspector. Now use a Segue from your new Initial View Controller and let it "push" to your TabBarController. To avoid a Warning rename the Segue.
After you have done this, you can add a UIBarButtonItem to every View, you like to add the SideMenu. In the Action Method of this UIBarButtomItem you only need to do this:
[self.menuContainerViewController toggleLeftSideMenuCompletion:^{}];
finally make sure you have a UIViewController or a UITableViewController, that is your "SideMenu" and set the right Storyboard ID.
if you are still need help, comment this...
and sorry for my english :)
You can use https://github.com/ozcanakbulut/VoovilSideMenu. It's easy to embed in a tabBarController. It uses Storyboard and Arc.

BannerViewController interferes with hidesBottomBarWhenPushed

I'm implememting a design based on the TabbedBanner example in the iAdSuite. I have a UINavigationController in the first tab. In that UINavigationController I have a view controller that simply has a button that pushes to another view controller. The pushed view controller is set to Hide Bottom Bar On Push in Interface Builder.
Here is the code where I'm setting up the UITabBarController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:#"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
_tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"TabBarController"];
_tabBarController.delegate = self;
FirstViewController *firstView = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstView];
_tabBarController.viewControllers = #[[[BannerViewController alloc] initWithContentViewController:firstNav], ];
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Everything works except the TabBar does not get hidden when I push to the next view controller. I have tried hiding the TabBar using the Interface Builder check box as well as using nextViewController.hidesBottomBarWhenPushed = YES and neither way works.
If I remove the BannerViewController implementation, the TabBar hides exactly as it should.
It seems to me that the BannerViewController is interfering with the UINavigationController being able to hide the TabBar.
Is it possible to use Hides Bottom Bar When Pushed to hide the TabBar in this type of setup?
Thanks
Note: I realize that the code above only has one tab. I removed the other tabs for clarity.
I think this is happening because the BannerViewController itself is just a container viewController and it never actually pushes another view controller. The view controllers are pushed within the container.

Resources