How to commonly use a storyboard's view component? - ios

I have a storyboard with a view controller(Menu View Controller), in which if the navigation bar’s menu button is pressed, a menu like view slides into the screen. I achieved this by animating the trailing constraint of the left menu view, from 0 to a value and vice-in-versa.
The storyboard looks like,
Now, by this method I have a slide-in slide-out menu view,
end result is like,
now what if I need to use it as a common component in more than one view controllers?
Can I have this menu view controller in a separate storyboard and then refer it from my another view controller?
Should I include the left menu view in every view controllers or is there any other smart ways to achieve this?

Use MMDrawer controller library which is best suitable for you and easy to integrate. Which can provide you left drawer and right drawer and which you can use in multiple controller.
Also you can manage these 2 components in 2 different VC so it will be easy to manage code.
To integrate follow this link:
https://github.com/mutualmobile/MMDrawerController

I recommend checking out this AppCoda tutorial. This tutorial explains how to use the SWRevealViewController, which is a "A UIViewController subclass for revealing a rear (left and/or right) view controller behind a front controller". Both the Github page and the AppCoda tutorial explain on how to implement this side menu. This solution is super simple and very reusable!
UPDATE: Added more context around the external link.

Related

Xcode 6 - Swift - Custom Tabbar with Navigation

I'm trying to create a tabbed application with navigation elements inside the tab bar, as seen in the picture below (the red bar) using Swift/XCode 6.2. Basically those three icons in the middle will direct the user to different view controllers. The other two icons would be context-based. For example, on a table view page you would see the menu icon and add new icon as seen in the image. However, clicking on a row would change the menu icon to a back icon, and the add icon to something else.
That's the general idea, but I'm having a very hard time implementing something even close to this. The first issue is that whenever I embed a view in a Tab Bar Controller, I can't move the tab bar to the top. However, when I create a custom UITabView in a View Controller, Control + Click and dragging a Tab Bar Item to another view doesn't create a segue. I haven't even begun to tackle having the navigation elements inside the bar.
I guess what I'm asking is just for a little guidance on what route to take to tackle this. I'm assuming I can't use a Tab Bar Controller or Navigation Controller because it doesn't seem like I can customize them all that much. So custom Tab Bar and Navigation Bars, and then implemnt the segues and button changes programmatically?
Thanks.
I will try to guide you from an architectural perspective (so you won't find much code below).
Using a UITabBarController
In order to achieve what you are suggesting, you are right you cannot use a UITabBarController straight away, among several reasons, the most immediate one is that they are meant to be always at the bottom and you want it in top (check Apple's docs). The good news is that probably you don't need it!
Note: If you still want to go with a UITabBarController for whatever reason, please see #Matt's answer.
Using a UINavigationController
You can use a UINavigationController to solve this task, since the UINavigationBar of a UINavigationController can be customized. There are multiple ways on how you can organize your view's hierarchy to achieve what you propose, but let me elaborate one option:
To customize a UINavigationBar's to add buttons, you just need to set its navigationItem's title view:
// Assuming viewWithTopButtons is a view containing the 3 top buttons
self.navigationItem.titleView = viewWithTopButtons
To add the burger menu functionality on a UINavigationController you can find several posts on how to do it and infinite frameworks you can use. Check this other SO Question for a more detailed answer (e.g. MMDrawerController, ECSlidingViewController to mention a couple).
About organizing your view hierarchy, it really depends on if when the user taps one of the main top buttons, it will always go to the first view controller in the new section or if you want to bring him back to the last view in the section where he was.
3.1 Switching sections displays the first view of the new section
Your app's UIWindow will have a single UINavigationController on top of the hierarchy. Then each of the 3 top buttons, when tapped, will change the root view controller of the UINavigationController.
Then, when the user changes section, the current navigation hierarchy is discarded by setting the new section view controller as the UINavigationController root view controller.
self.navigationController = [sectionFirstViewController]
3.2 Switching sections displays the last displayed view in the new section
This will require a slightly modified version of the above, where your each of your sections will have its own UINavigationController, so you can always keep a navigation hierarchy per section.
Then, when the user taps one of the top buttons to switch section, instead of changing as previously described, you will change the UIWindowroot view controller to the new section's UINavigationController.
window.rootViewController = sectionNavigationController
Using a custom implementation
Of course, the last and also very valid option would be that you implement yourself your own component to achieve your requirements. This is probably the option requiring the biggest effort in exchange of the highest customizability.
Choosing this option is definitely not recommend to less experienced developers.
I'd like to take a stab at this--I think it is possible to use a tab bar controller here.
Your topmost-level view controller will be a UITabBarController with a hidden UITabBar.
Each tab is contained in a UINavigationController.
All view controllers in the navigation controller will be a subclass of a view controller (say, SwitchableViewController).
In SwitchableViewController's viewDidLoad, you set the navigation item's title view (i.e. whatever's at the center; self.navigationItem.titleView) to be the view that holds the three center buttons. Could be a UISegmentedControl, or a custom view.
Whenever you tap on any of the buttons, you change the topmost UITabBarController's selected index to the view controller you want to show.
Issues you may encounter:
Table views inside tabs will have a scrollIndicatorOffset at the bottom even if the tab bar is hidden.
Solution: Play around with the automaticallyAdjustsScrollViewInsets of the tab bar controller, or the inner view controller. https://stackoverflow.com/a/29264073/855680
Your title view will be animated every time you push a new view controller in the navigation stack.
Solution: Take a look at creating a custom transition animation for the UINavigationController.

How to build navigation controller from existing view controllers drew in storyboard?

I have built some view controllers in storyboard like in the picture below
I already implemented the data inside them, modal segue is used for transitions in between. Now I just realise when I push "back" button, previous view won't be properly loaded. I figure I should switch to navigation controller and add those controllers in stack instead. But I don't know how to go from where I am now.
I think I should make changes programmatically because I found building navigation controller in storyboard won't have much variation in UI design (at least I don't know how to implement existing pages in that way). So what should I do to implement programmatically? Please help me, thanks!
Select Category View Controller and go to menu: Editor > Embed In > Navigation Controller. Then change segues style from Modal to Push.

"Slide" segue between UITabBar views

My iOS 5 app uses storyboarding with a UITabBarController. There are three "tabs" each displaying a view controller which has been linked using a relationship back to the UITabBarController. At the moment each view controller appears when you tap the relevant tab, as expected. However, for a more gracious transition I would like to slide the view controllers on and off screen.
By way of example, if I am currently on Tab 0 and then select Tab 1 the view controller on screen (for Tab 0) should slide off to the left-hand side of the screen, and the new view controller (for Tab 1) should slide on from the right-hand side of the screen.
I have been able to achieve this behaviour using a custom UIView as the tab bar but would like to know whether this is possible with a custom segue in storyboarding, as that would certainly save a lot of coding (and also would keep things a fair bit neater in the project)?
Thanks in advance for any assistance.
I am trying to do the same thing.
Unfortunately I think the relationship segue does not allow any customization as it just connect tab bar and the tab bar items together, and not a transition.
My guess is we have to do the transition ourselves when the view appeared.

Adding UIPageView as a portion of a screen

Pretty new to iOS development and curious whether something is possible and if so the best want to do it.
I'd like to make a UIPageViewController be a portion of the screen. I.e., I want to have a menu bar, perhaps some additional controls and then place the page view controller on a portion of that page (so the menu bar isn't part of the page turning control). In other words, a UIPageView that acts like a scrollView that doesn't take up the whole screen.
Acceptable design?
Thanks.
Yes, this is possible, and the implementation is very easy.
Steps (implemented in XCode 6 using Storyboards)
Begin with an empty view controller.
Add a Container View from the object library on the right. The Container View may automatically embed in a regular View Controller, in which case you can just delete the View Controller because we want to embed a Page View Controller.
Select a Page View Controller from the object library on the right, and place it wherever you want in your Storyboard.
Ctrl Click + drag from the Container View to the Page View Controller, and select embed from the menu that appears. The Page View Controller should automatically resize itself to be the same size as the Container View in the original View Controller.
A nice example from apple developer sample code: PageControl. Implemented with UIScrollView and UIPageControl.
Also you may want to create a new iOS project with template "Page-Based Application". The template code is implemented with UIPageViewController.
Both implementation employ View Controller Containment.
BTW: the is no UIPageView, only UIPageControl or UIPageViewController.
You can Try Below link for uipageviewcontroller Tutorial
http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_UIPageViewController_Application
U can Try uiview for pageturning not uiviewcontroller
u can add uiview to uiviewcontroller.
like [Self.view addSubview:youruiview];
and Remove uiview controller like [youruiview removefromsuperview];
Thanks..!

How can I change the Storyboard animation for modal in Xcode 4.2?

I am quite new to Xcode coding and I have been using Storyboard for along time, if you know when you link a button to a view and select the option "Modal" it will make a link with the animation of the new view coming up from the bottom. I was wondering if it was possible to change the animation to the new view coming from the right. I am sorry this question was so brief, if you need more info just ask me.
Thanks.
If you select the segue and look at the Attributes Inspector (on the right side of the window), you will see a pop-up menu labeled Transition. This menu lists the available transition styles for the segue:
Cover Vertical
Flip Horizontal
Cross Dissolve
Partial Curl
If you want a different style of transition, you will need to use a different type of segue. If you have a UINavigationController hosting your source view controller (the one that contains the button), you can use a Push segue, which slides the new view in from the right. If you don't have a navigation controller or don't like the Push segue animation, you'll have to implement a custom segue to change the animation.
More on custom segues
Custom Segue- Apple
Custom Segue + CATransition
-anoop

Resources