SWRevealViewController hiding rear view controller - ios

I am designing a slide out menu using SWRevealViewController. I have a TableViewController with static cells to be my rear view controller. The table view goes like -
I want my slide out menu to be like this only but instead I get something like this as SWRevealViewController cuts some part of my rear view conroller -
I want that my slide menu must have a full display of my rearViewController still showing the open button. Please give suggestions or code if possible. Thanks in advance.

If you want a full width rearViewController, you can do this:
Go to -(void)_initDefaultProperties in SWRevealViewController.m class.
Change _rearViewRevealWidth = 260.0f; to _rearViewRevealWidth = [UIScreen mainScreen].bounds.size.width;
You can also modify other dimensions in same method.

That's why because it has 260 as width static value and to change that you need to open SWrevealviewcontroller.m file , scroll to line 647 and change the width of the _rearViewControllerWidth from 260 to 360 for example !
Good luck !

There is one property named rightViewRevealWidth in SWRevealViewController. You can change its value.
in your first viewController add below line in viewDidLoad()
self.revealViewController().rightViewRevealWidth = self.view.bounds.size.width - 80.0;

Related

Create a submenu iOS

I want to create a submenu that will appear right next to the first menu and that will contain more options. The first menu is hidden and only appears when a button its clicked on the navigation bar, i used the SWRevealViewController from github for the first menu, but i can't make the second one appear . Can somone help ?
Thanks for any help in advance
Basically you add another SWRevealController as front view controller of the root SWRevealController.
UIViewController *secondRearVC = // your second level menu controller
UIViewController *secondVC = // your second level front view controller
SWRevealViewController *childRevealController =
[[SWRevealViewController alloc] initWithRearViewController:secondRearVC frontViewController:secondVC];
[rootRevealController setFrontViewController:childRevealController animated:YES];
You can find example of what I've suggested here.
Other option is using other side menu controller, JASidePanels, if I'm not wrong it does what you want. Anyway you'll end up using some UIViewController containers recursively, so it's just a matter of choice.
For this effect i have created a separate view say reveal view with UITableView init, at first i am giving zero width and full height for that view. If the navigation button is pressed , i am moving the main view to right like about 100px and change the width of the reveal view to 100px, place that code in animation block.
[UIView animateWithDuration:0.5 animations:^{
//Move frame or transform view
revealView.frame = CGRectMake(0,0,1,screenHeight);
mainView.frame = CGRectMake(0, 0, 320, screenHeight);
}];

how to show an overlapping view iOS

I have a view with some UI components and a button on it, upon touch of a button I want to show a half view with some textfields on it overlapping the initial view, the initial view should be visible partly , the overlapping view will cover only half screen from bottom. Is this possible ?
I don't have any code as I am unable to figure out what it needs to be done, as we show any view it covers the entire screen.
Thanks
there are several ways you can do this, here are two:
1) add a popover controller that gets displayed on your button press:
here's some apple documentation on popovers: https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/Popovers.html
2) add the new view as a subview to your UIViewController
PROGRAMICALLY:
in the viewDidLoad function you can do the following to initialize the halfScreenView
GLfloat topOffset = self.view.frame.size.height/2;
UIView halfScreenView = [[UIView alloc] initWithFrame: CGRectMake(0, topOffset , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - topOffset)
[self.view addSubview:halfScreenView];
-more logic might be needed if you support Landscape orientation, you can always re-assign the location of the view with halfScreenView.frame.origin and halfScreenView.frame.size
-initially you can have this view be hidden
halfScreenView.hidden = YES;
-when you click the button it will show the overlaying view:
halfScreenView.hidden = NO;
USING STORYBOARD:
you can also set up your overlaying view in the storyboard if you have one
-drag a UIView into your UIViewController and set it up where you want it to be located
-initialize the view to be hidden by checking the hidden box in the attribute inspector
-add the view as a property to your view
-manage when to show this view with self.halfScreenView.hidden
-this technique allows you to customize what is inside the new view within the storyboard which is nice
FOR BOTH:
-be careful with layers, you don't want your view to show up behind the one you already present. In the storyboard the last thing inserted goes on top. With in the code you can always access/change the views z position with halfScreenView.layer.zPosition (higher z values are on top)
First create a new class subclassing UIViewController called SecondView (or whatever you want), then design the UI the way you want (in its .xib file)
Then go to your main view controller's file and make an IBAction for that button.
In that method, write:
SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height/2, height, width);
[self.view addSubview:second.view];
This will add it to the bottom half of the screen. Put your own parameters for its height and width. When you want to dismiss the view, you can do this inside your SecondView class
[self.view removeFromSuperview];
You can deal with the textFields from within the SecondView class and have them communicate with your other view by doing the following in SecondView.h
#property IBOutlet UITextField* textField;
Hope this helps!
Yes, assuming you are using Interface Builder, go ahead and build the overlapping view and hook up all of the IBOutlets and IBActions. Say this view is called myView. Set myView.hidden = YES and myView.enabled = NO. This hides and disables myView so that it isn't even there from the user's perspective. In the appropriate button's IBAction, change the hidden and enabled properties to YES. That will make the view visible and active again.

how do I display different views in a view controller using a tab bar

I have a view controller that has a map view and a second view under the a tab bar. How do I go about updating the second view when I press buttons on the tab bar?
I tried:
LocationNotesViewController lnvc = new LocationNotesViewController();
lnvc.View.Frame = MainPageTabBarView.Frame;
MainPageTabBarView = lnvc.View;
Nothing happens...the view doesn't update.
I want to update the second view with different things when a user clicks on the tabbar...
If you put a UIView underlying whatever data you want displayed in it, you can use the IBAction of the tabBar to programtically cahnge out the contents of the UIView.
Or you could have the IBActions of the tabbar create new UIViews on the fly, containing whatever you want inside.
Code to do this would be like explained here: http://www.programmerscountry.com/creating-uiviewcontrols-programatically/.
Not exactly the same, but you will understand how it works from that answer.
To switch UIViewControllers use this piece of code:
UIViewController *viewController =
[self.storyboard instantiateViewControllerWithIdentifier:#"4"];
[self presentViewController:a animated:YES completion:nil];
I think this is a work around - but I was able to make this happen by doing:
LocationNotesViewController lnvc = new LocationNotesViewController();
lnvc.View.Frame = new RectangleF(MainPageTabBarView.Frame.X, MainPageTabBarView.Frame.Y - MainPageTabBarView.Frame.Y, MainPageTabBarView.Frame.Width, MainPageTabBarView.Frame.Height);
MainPageTabBarView.AddSubview(lnvc.View);

How do I stop the SearchBar to open on my UITableView instead of over my entire view?

I'm working on an App which main view consists of a MapView and a TableView, similar to the interface of the Foursquare-App. Now the problem I have is that when I hit the search bar of the App, the search window opens over the entire screen - but I'd only want it to open over the TableView.
Does any of you have an idea how to change the behaviour of the SearchBar so that it only laps over its "own" tableView and not the map view?
Here's the two images basicly describing the problem:
//The view without search. The search should come up over the table view.
// but it does not instead covers the whole map.
//Short edit: The map is actually a MapBox map, shouldn't change anything on the topic.
This is a very interesting question... I never tried something like this but I think that a possible way to do could be:
create a view controller with a searchDisplayController that I'll call SearchViewController
SearchViewController *searchVC = [[SearchViewController alloc] init]
and on the view controller that contain the map
[self addChildViewController:searchVC];
// assuming an Y offset of 200 pixel, but you can get the mapView height ... it's better
searchVC.view.frame = CGRectMake(0.0f, 200.0f, self.view.frame.size.width, self.view.frame.size.height-200);
[self.view addSubview:searchVC.view];
if ([searchVC respondsToSelector:#selector(didMoveToParentViewController:)]) {
[searchVC didMoveToParentViewController:self];
}
This probably will not work perfectly but could a starting point... a I said I never tried, let me know if it works
You add your search bar on view I think
you need to add search bar on HeaderView of table view
I think it will be work..

How to get the height of the tabbar programmatically?

I've found out that the height of a UITabBar is 49px (or 50px, depending on the source).
Because I don't like to use too much hard-coded values in my code I was wondering if it is possible to retrieve the height of the tabbar programmatically.
Kind regards,
Niels R.
PS: The reason I'm asking is because I have a view controller (with a list view containing text fields) that is either simply pushed by the navigationcontroller (pushViewController) or presented as a modal (presentModalViewController). As soon as the keyboard show up, the size of the view is reduced, but I have to take into account that the tabbar is only visible when the view controller is pushed and not presented as a modal.
I don't totally understand your P.S., but you can do:
tabBarController?.tabBar.frame.size.height
If you want to get the standard height for the UITabBar control then you can do:
UITabBarController *tabBarController = [UITabBarController new];
CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;
prettier
CGRectGetHeight(self.tabBarController.tabBar.frame)
check this in your vc
bottomLayoutGuide.length
In Swift 3, you can retrieve the height of the UITabBar with this code below.
self.tabBarController!.tabBar.frame.size.height
Which will return a CGFloat value of the height
If an object is based on UIView (which most visual elements in the library are), you can get the size from the ivar "frame".
UITabBar is inherited from UIView as long as you mhave access to your UITabBar instance you can access and modify the frame of UITabBar,
CGRect myRect = myTabBar.frame;
Try to use the intrinsicContentSize property of the tab bar like this
let tabBarHeight = self.tabBarController.tabBar.intrinsicContentSize.height

Resources