UIView transitions present modal view at the bottom - objective-c

I need to display a UIView/UIViewController when the user taps a button and the modal view should appear just like how the key board appears from the bottom bar when you edit text in a UITextField. Using the following code, I get to show it as a pop up.
[self presentModalViewController:child animated:YES];
How to make it appear like the keyboard?
I understad modal views cover the entire screen. But I really want a view that covers only half the screen. So, please tell me why this doesn't work
MyController *controller = [[MyController alloc] initWithNibName:#"MyView" bundle:nil];
CGRect frame = CGRectMake(0,44,768,264);
[controller view].frame = frame;
contoller.delegate = self;
[[self view] addSubView:[controller view]];
[controller release];
I am trying to add a sub view to my current view and make it appear where the keyboard appears.

Check if your child.modalTransitionStyle == UIModalTransitionStyleCoverVertical.
(And a model view controller always cover the whole screen. If you just need to cover half of the screen like the keyboard, you need to put the view controller's view as a subview of the main view, then animate it in manually with animation blocks.)

I know its an old question, but an answer to this is to use a UIActionSheet.
It won't present a View Controller, but you can present custom views that only cover a portion of the screen.
Check out this question for more information
Add UIPickerView & a Button in Action sheet - How?

Related

iOS7 - popToRootViewControllerAnimated not doing anything

I have looked around but haven't found a satisfying answer. My problem is that whenever I call popToRootViewControllerAnimated:(BOOL) it is not doing anything. When I NSLog it, it logs (null).
Let me back up a bit here. I have a table view controller that has a list of things, at the navigation bar up top there is an option to add and that takes me to a new view controller with a segue "Present as PopOver" which gets rid of the principal or main navigation bar. So I made one manually and added 2 bar button items "Cancel" and "Add". When "Cancel" is tapped, it should take the user back to the table view controller and discard changes, when "Add" button is tapped, it should also take user back to the previous table view controller with the changes. But it's not doing anything.
Here is my code.
- (IBAction)cancelButton:(UIBarButtonItem *)sender {
UINavigationController * navigationController = self.navigationController;
NSLog(#"%#", navigationController);
NSLog(#"cancel tapped though");
ListingTableViewController *rootController = [[ListingTableViewController alloc] init];
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:rootController animated:YES];
}
As far as the segue, this view controller is not connected to anything, or should I connect it? This is a noobish question indeed. Here is my xcode screenshot.
Check this link for the screenshot of the storyboard
http://i.stack.imgur.com/lqnCF.png
You must call
- (IBAction)cancelButton:(UIBarButtonItem *)sender {
NSLog(#"cancel tapped though");
[self dismissViewControllerAnimated:YES completion:nil];
}
instead of popToRootViewControllerAnimated because your VC presented and not pushed!
When presenting a view, you are not pushing it in your navigation controller, but having it presented. To dismiss it, try using [self.presentingViewController dismissViewControllerAnimated:NO completion:nil].

What is best approach to add back button for first view controller in navigation controller?

I'm beginner iOS developer, so don't know how to solve my problem correctly. I have one navigation controller and want to make modal transition to another navigation controller that will have back button on it's first view controller.
In my first navigation controller I made this:
InfoViewController *destinatinViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
[self presentViewController:destinatinViewController animated:YES completion:nil];
InfoViewController is UINavigationViewController.
Then I made this in InfoViewController (second navigation controller):
InfoRootViewController *rootViewController = [[InfoRootViewController alloc] initWithNibName:#"InfoRootViewController" bundle:nil];
[self pushViewController:rootViewController animated:NO];
For now I know how to add button to go back, but it has not styling (certainly arrow). As I understand because it is only one view in stack of second navigation controller.
So, I need your help to add styled back button for first view controller of navigation controller, because I don't want to make own styling (I'm lazy).
Thanks, for any advance!
PS: I made modal transition because, it has animations like from bottom or top. I tried to use custom animations for pushViewController, but in iOS 7 they're working not correctly.
I'll let someone else help you with the back button issue because I think it's a mistake to create one for a modal view controller that's presented from the bottom of the screen. Typically, such a modal view controller is dismissed with a cancel button or its equivalent. If you really think that you need a back button then you should probably push the view controller onto the existing navigation stack instead of presenting it modally.
However, I am happy to show you how to properly alloc/init a navigation controller and then present it.
I don't know why you're subclassing UINavigationController, but I'm going to pretend that you don't need to (which is probably the case).
InfoRootViewController *rootViewController = [[InfoRootViewController alloc] initWithNibName:#"InfoRootViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[self presentViewController:navController animated:YES completion:nil];

Mimic modal window to allow for tapping outside of modal window

I am using a Split View Controller and showing a modal window when a button is tapped in the master pane. I need to be able to dismiss the window when the user taps outside of the bounds of the window.
I am currently using presentViewController, which I have read does not allow for taps outside of the window.
I think I need to present a view controller myself and setup a gesture recognizer to handle the closing from there... the trouble is, I don't know where/how to present the view controller or where to attach the gesture recognizer to in an SVC.
I setup my view controller like this:
SearchViewController *searchViewController = [[SearchViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:searchViewController];
[navController setNavigationBarHidden:NO];
From there I don't know how to make the view controller appear without using presentViewController. I have tried the following (each separately):
[[self navigationController] addChildViewController:navController];
[self.view.window.rootViewController addChildViewController:navController];
[self.presentingViewController addChildViewController:navController];
[self.presentingViewController.presentingViewController addChildViewController:navController];
How do I present my navcontroller, and which view would I add a gesture recognizer to?
A UIPopoverViewController will work.
Alternatively, you can add a child view controller to your RootViewController. . (Check out UIViewController containment for lifecycle handling).
Basically just this in your root view controller:
- (void) presentSemiModalViewController
{
//Tint-out the background or blur it with some effect
_semiModalViewController = viewController;
//Choose the frame you'd like to use here, and an animation you'd like to use to present it
[self.view addSubView:_semiModalViewController.view];
[_semiModelViewController willMoveToParentViewController self];
}
If the RootViewController is not yours (eg a UINavigationController) you can use a category, but to retain the _semiModalViewController you'll need to use an associative reference (ie add a "property" to the category to store the modal VC while its in use). For info on that see here: Associative References Info
PS: You might want to choose a better name my "semi-modal", but you get the idea ;)

How do I add a navigation bar's Done button to a popover's passthroughViews?

I'm working in an iPad app that has a split view with a navigation controller in the detail view. The deepest view that can be in the navigation stack is an edit view where the user can edit data. I put an edit button as the rightBarButtonItem and when editing starts, change it to a done button.
When editing commences and the user touches on a particular field, I present a popoverview with a list of possible choices filtered by what they are typing - a form of autofill based on all the values of that field in all other objects.
This works fine, except if you try touching on the done button. The popover eats this touch and dismisses itself. So the user has to touch done again.
I tried using the uipopovercontroller's passthroughViews property, but UIBarButtonItem is not a view and there is no documented way to get the view for the done button or even the navigation bar. I can access the variable in gdb, but it isn't accessible via KVC.
Any ideas on how I can prevent the need to tap done twice?
I've thought about a gesture recognizer on the window, but that seems messy and I'd have to handle rotation.
In case anyone gets here from google, copypaste from other question:
The only solution I found for now is to create UIBarButtonItem with custom UIButton using
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//code for styling button
UIBarButtonItem *b = [[[UIBarButtonItem alloc]
initWithCustomView:button]
autorelease]
and then
popoverController.passthroughViews = [NSArray arrayWithObject:b.customView];
But be prepared - you cannot create UIButton that looks like UIBarButtoItem. I ended up with creating image that reassembled UIBarButtonItem.

How to open an UIView in fullscreen mode with a tabbar?

this is my problem.
I have a tabBar application.
In first tab, i have a table.
On click on table it shows a modal
view.
To go back from modal view to first
view, i use
[self presentModalViewController:nw animated:YES];
The problem is that if i click on the tabbar while is opened a modal view, it opens second view, but first view's table don't work because the modal view is still opened althoug it appear as closed.
It's a way to open modal view in fullscreen covering the tab bar?
Or also to check if modal view is closed or not from another view?
EDIT:
I tried with all of this code:
nw = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
nw.modalInPopover = YES;
nw.wantsFullScreenLayout = YES;
nw.hidesBottomBarWhenPushed = YES;
nw.contentSizeForViewInPopover = CGSizeMake(320, 480);
nw.modalPresentationStyle = UIModalPresentationFullScreen;
nw.view.frame = [[UIScreen mainScreen] applicationFrame];
[nw.view setNeedsLayout];
but nothing!!! It wan't go in fullscreen!!
Any idea please?
thanks,
alberto
If the view you're presenting is full screen, this should obscure the tab bar. That said, you might need to re-size the view programmatically so that it's the same size as the UIWindow.
You should be able to do something along the lines of...
[nw setFrame:[[UIScreen mainScreen] applicationFrame]];
[nw setNeedsLayout];
...to achieve this. (Sorry, I'm on a Windows box at the moment, so I can't confirm this. Hopefully someone will provide any tweaks if required.)
You should then dismiss the initial modal view via a delegate method in the originating class. (See the "Dismissing a Modal View Controller" section of Apple's View Controller Programming Guide for iOS.) The originating class would then dispose of the modal view.
Resolved using notification!
When a tab change, i send a notification and close the modal controller.
- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController {
[[NSNotificationCenter defaultCenter] postNotificationName:#"DataComplete" object:nil];
return YES;
}
In my view classes receive a notification and dismiss the controller!
- (void)downloadDataComplete:(NSNotification *)notif {
NSLog(#"Received Notification");
[self dismissModalViewControllerAnimated:YES];
}
Now it's possibile to reopen a modal view also changing tab!
This is a workaround but works!
alberto.