Bring UIView over the current UIVIewController on a NavigationApplication - ios

I develop a project which is based on navigation structure.
It is intended that in the current ViewController to display a generic view.This view contains information about the menu of the application.
I must show this uiview when user tap a button from the navigation bar.
I can't display this view over the current viewcontroller.
Can anyone help me?
I have a customNAvigation "
#interface CustomNavigation : UIView
- (IBAction)goToProfileInRootVC:(id)sender;
- (IBAction)goToRootinRootVC:(id)sender;
- (IBAction)goToPreviewVC:(id)sender;
- (IBAction)goToMenu:(id)sender;
+ (CustomNavigation*)showInView:(UIView*)parentView;
#end
When user tap on the Menu button from the navigtion I must display an UIView which must contain a list with the categories from menu.
This view must be displayed over the current UIViewcontroller.

I just give you basic suggestion,
Add You view (custom) in self.view (as Hidden), such like
self.mycustomView.hidden = YES; // default is hidden;
[self.view addSubView:self.mycustomView];
on Button click method, make this mycustomView is as visible
-(void)btnClick:(UIButton *)sender
{
self.mycustomView.hidden = NO;
}

Related

UITableView inside childviewcontroller not receiving all taps

I've got a UITableview that displays the search results of a UISearchController. They are inside of a Childviewcontroller.
I write the text on the textfield of the parentviewcontroller and it passes the text to the searchbar of the child view controller.
This all works fine.
But for some reason, when I am choosing a result in the child view controller's tableview, it is not very responsive.
After typing in the search text in the textfield (having the textfield as the firstResponder), most of the times I have to tap more than once to select a row.
(P.S. userInteraction is enabled, otherwise no touch would ever go through.)
Any idea why?
I have same problem, and my solution is:
- (void) displayContentController: (UIViewController*) content{
[content.view setFrame:recorderView.bounds];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:content];
childNavController.toolbarHidden = NO; // if you show toolbar
childNavController.view.frame = content.view.frame;
[self addChildViewController:childNavController];
[recorderView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
}
content is my subViewController
Is this for Swift or for Objective-C? Also are you placing a UI Tap Gesture Recognizer on the views that you wish to be touchable?

Show the other view controller in one common view controller like slide menu

I have one view controller called homeviewcontroller. In that i placed one right bar button item And i have added one uiview under that bar button item. when i click my bar button item it will show the uiview.In that uiview i have two button option.
A view controller
B view controller
I also create a two view controller with story board identifier. Avc , Bvc. So what i need is. When i click the buttons in my UIVIEW that respective A Viewcontroller or B viewcontroller should show in my `home Viewcontroller'. I have that two button action like this:
- (IBAction)ButtonONEClicked:(id)sender {
}
- (IBAction)ButtonTwoClicked:(id)sender {
}
How can i code that to show that two A Viewconroller and B viewcontroller in my homeViewcontroller.Here is my image of that uiview placed in my HomeViewcontroller
Please help me how to do that.Thanks
have you used container view controller -
if not so here -
1.https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
Best Tutorial - a.https://spin.atomicobject.com/2015/07/21/ios-container-views/
b.http://www.thinkandbuild.it/working-with-custom-container-view-controllers/
Swift version - https://github.com/codepath/ios_guides/wiki/Container-View-Controllers-Quickstart

Display UIViewController as Popup in iPhone

Since there is no complete, definitive answer to this common recurring question, I'll ask and answer it here.
Often we need to present a UIViewController such that it doesn't cover full screen, as in the picture below.
Apple provides several similar UIViewController, such as UIAlertView, Twitter or Facebook share view controller, etc..
How can we achieve this effect for a custom controller?
NOTE : This solution is broken in iOS 8. I will post new solution ASAP.
I am going to answer here using storyboard but it is also possible without storyboard.
Init: Create two UIViewController in storyboard.
lets say FirstViewController which is normal and SecondViewController which will be the popup.
Modal Segue: Put UIButton in FirstViewController and create a segue on this UIButton to SecondViewController as modal segue.
Make Transparent: Now select UIView (UIView Which is created by default with UIViewController) of SecondViewController and change its background color to clear color.
Make background Dim: Add an UIImageView in SecondViewController which covers whole screen and sets its image to some dimmed semi transparent image. You can get a sample from here : UIAlertView Background Image
Display Design: Now add an UIView and make any kind of design you want to show. Here is a screenshot of my storyboard
Here I have add segue on login button which open SecondViewController as popup to ask username and password
Important: Now that main step. We want that SecondViewController doesn't hide FirstViewController completely. We have set clear color but this is not enough. By default it adds black behind model presentation so we have to add one line of code in viewDidLoad of FirstViewController. You can add it at another place also but it should run before segue.
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
Dismiss: When to dismiss depends on your use case. This is a modal presentation so to dismiss we do what we do for modal presentation:
[self dismissViewControllerAnimated:YES completion:Nil];
Thats all.....
Any kind of suggestion and comment are welcome.
Demo :
You can get demo source project from Here : Popup Demo
NEW : Someone have done very nice job on this concept : MZFormSheetController
New : I found one more code to get this kind of function : KLCPopup
iOS 8 Update : I made this method to work with both iOS 7 and iOS 8
+ (void)setPresentationStyleForSelfController:(UIViewController *)selfController presentingController:(UIViewController *)presentingController
{
if (iOSVersion >= 8.0)
{
presentingController.providesPresentationContextTransitionStyle = YES;
presentingController.definesPresentationContext = YES;
[presentingController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}
else
{
[selfController setModalPresentationStyle:UIModalPresentationCurrentContext];
[selfController.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
}
}
Can use this method inside prepareForSegue deligate like this
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
PopUpViewController *popup = segue.destinationViewController;
[self setPresentationStyleForSelfController:self presentingController:popup]
}
Modal Popups in Interface Builder (Storyboards)
Step 1
On the ViewController you want as your modal popup, make the background color of the root UIView clear.
Tip: Do not use the root UIView as your popup. Add a new UIView that is smaller to be your popup.
Step 2
Create a Segue to the ViewController that has your popup. Select "Present Modally".
Two Methods To Create Popup From Here
Method One - Using the Segue
Select the Segue and change Presentation to "Over Current Context":
Method Two - Using the View Controller
Select the ViewController Scene that is your popup. In Attributes Inspector, under View Controller section, set Presentation to "Over Current Context":
Either method will work. That should do it!
You can do this in Interface Builder.
For the view you wish to present modally set its outermost view background to transparent
Control + click and drag from the host view controller to the modal view controller
Select present modally
Click on the newly created segue and in the Attribute Inspector (on the right) set "Presentation" to "Over Current Context"
Feel free to use my form sheet controller MZFormSheetControllerfor iPhone, in example project there are many examples on how to present modal view controller which will not cover full window and has many presentation/transition styles.
You can also try newest version of MZFormSheetController which is called MZFormSheetPresentationController and have a lot of more features.
You can use EzPopup (https://github.com/huynguyencong/EzPopup), it is a Swift pod and very easy to use:
// init YourViewController
let contentVC = ...
// Init popup view controller with content is your content view controller
let popupVC = PopupViewController(contentController: contentVC, popupWidth: 100, popupHeight: 200)
// show it by call present(_ , animated:) method from a current UIViewController
present(popupVC, animated: true)
Imao put UIImageView on background is not the best idea . In my case i added on controller view other 2 views . First view has [UIColor clearColor] on background, second - color which u want to be transparent (grey in my case).Note that order is important.Then for second view set alpha 0.5(alpha >=0 <=1).Added this to lines in prepareForSegue
infoVC.providesPresentationContextTransitionStyle = YES;
infoVC.definesPresentationContext = YES;
And thats all.
Swift 4:
To add an overlay, or the popup view
You can also use the Container View with which you get a free View Controller ( you get the Container View from the usual object palette/library)
Steps:
Have a View (ViewForContainer in the pic) that holds this Container View, to dim it when the contents of Container View are displayed. Connect the outlet inside the first View Controller
Hide this View when 1st VC loads
Unhide when Button is clicked
To dim this View when the Container View content is displayed, set the Views Background to Black and opacity to 30%
You will get this effect when you click on the Button
You can do this to add any other subview to the view controller.
First set the status bar to None for the ViewController which you want to add as subview so that you can resize to whatever you want. Then create a button in Present View controller and a method for button click. In the method:
- (IBAction)btnLogin:(id)sender {
SubView *sub = [[SubView alloc] initWithNibName:#"SubView" bundle:nil];
sub.view.frame = CGRectMake(20, 100, sub.view.frame.size.width, sub.view.frame.size.height);
[self.view addSubview:sub.view];
}
Hope this helps, feel free to ask if any queries...

How to alternately switch views in same controller (view need to be all over screen)?

I am practicing ios and I am trying to make simple real estate app, one viewcontroller, I put navigation bar and at the right sie of navigation bar I have button map
(I am trying to show all houses in area with basic data:street, price, long, lat... in tableview and just like marker on mapview).
I want that button to behave like toggle, to switch between table view and map view but in same controller. ( In android I could put one below other and just alternately set visibility to gone to one and visible to another).
How to alternately switch views in same controller (view need to be all over screen) ?
just assign the newView to oldOne
UIView *generalView=[UIView alloc]init];
[self.view addSubView:generalView];
when you want to show tableView ,then just assign
generalView=tableView;
and when you want map, then
generalView=mapView;
Are you using a storyboard? Why not just perform a segue on button tap?
- (void)myButtonMethod
{
//execute segue programmatically
[self performSegueWithIdentifier: #"MySegue" sender: self];
}
"MySegue" would be the segue identifier that is set in the storyboard between the two views.
Add two views tableview and maple to UIViewController's view.
It would be like:
-(void) viewDidLoad
{
[self.view addSubview:tableView];
[self.view addSubview:mapView];
}
On button click decide which view needs to be displayed:
-(void) onButtonClick:(UIButton *)sender
{
//If you want to display map..
[self.view bringSubviewToFront:mapView];
//If tableview needs to display
[self.view bringSubviewToFront:tableView];
}

Push view controller after setting view

Suppose i have a uiview in 1 screen and i want to view the same view in fullscreen mode on click of a button.
On click of a button the following function is called.
-(IBAction)fullScreen
{
FullScreenViewController *mv = [[FullScreenViewController alloc] init];
mv.fullview = minimizedView;
//minimizedView is a UIView already created with a specified frame
// fullview is a UIView decalred in FullScreenViewController
[[self navigationController] pushViewController:mv animated:YES];
}
In the FullScreenViewController.m the viewDidLoad function is as follows :
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:fullview];
}
On click of the fullscreen button, the view appears but on click of back button, the minimized view in the previous page dissapears.
Is it wrong to do this?
You dont need to use two views to implement this. In your code, your are navigating from one view to another view. You dont need to do that. Your minimizeView itself having a property "setFrame:" to increase and decrease its frame to resize of that subview in your current view itself. Learn how to resize the UIView.

Resources