I use a TabBarController on my app, in one of the main views (aViewController) i push another controller (bViewController), and hide the TabBar using self.tabBarController.tabBar.hidden=YES;
bViewController have a button at the same place where the tabBar was, and it doesn't catch the touch event.
I have tried placing the button in different places of bViewController, and the area where the tabBar was supposed to be is the only place where touch event is not detected.
I have tried using bViewController outside the tabBarController and it works fine.
Any help would be appreciated.
EDIT:
When i press a button on aViewController i call
self.tabBarController.tabBar.hidden=YES;
[self performSegueWithIdentifier:#"aViewToBView" sender:self];
aViewToBview is a push segue declared on storyboard
For some reason you cannot touch the views underneath the tab bar.
However, if you hide the tab bar and then add a subview to it, the view can then receive user interaction!
This worked for me:
// Create a button that is at the very bottom of the screen
CGFloat buttonHeight = 45.0f;
UIButton *finishButton = [[UIButton alloc] initWithFrame:CGRectMake(
0,
self.view.frame.size.height - self.tabBarController.tabBar.frame.size.height - buttonHeight,
self.view.frame.size.width,
buttonHeight)];
//...more initialization of the button...
//Here is our solution:
[self.tabBarController.view addSubview:finishButton];
Related
I have a ViewController, which contains a button. In start-up, I rotate the window by PI radius. In appplication:didFinishLanchingWithOptions function add follow codes:
[application setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
self.window.transform=CGAffineTransformMakeRotation(M_PI);
self.window.bounds = CGRectMake(0, 0, 320, 480);
I hope click the button to popup a model view (by presentViewController function), but I only see a black screen. The button click event:
- (void)btnAction:(id)sender {
UIViewController *vc = [self.storyboard instantiate...WithIdentifier:#"modal";
[self presentViewController:vc animated:YES completation:nil]; // unexpected behavior
// [self.navigattionController pushViewController:vc]; // expected behavior
}
By debug I know the modal view's center has some offset but I can not correct it. When I use push segue to replace it, it has right behavior.
When you start your application you see black screen or after clicking button to show your modal view.
that is called black popup screen.
iOS - Right clicking on a View Controller in a Storyboard opens a menu, what does "manual" under Triggered Segues do?
How do you use it? I can't seem to find any info in the Class Reference.
PS. The answer might be obvious, but I haven't figured it out. Be gentle!
if you want to present a viewController by pressing a UIButton or an UITableViewCell
you nee to hold the key Control and Drag with your mouse from the button or UITableViewCell to the destination viewController, once the destination viewController turns to blue color release the mouse button and a popup should appear with the title Action Segue, select one of the segues and that's it, now you can access to your viewController without any line of code
the UIButton and the UITableViewCell works when the user taps on it but if you have a object that don't have the same behavior of the button like a UIImageView then the Action Segue won't be available
for that kind of situations you need to make a Manual Segue
inside storyboard hold the key Control and Drag with your mouse from the viewController to the destination viewController, once the destination viewController turns to blue color release the mouse button and a popup should appear with the title Manual Segue, select one of the segues and now you should see a line with an arrow and a circle in the middle, click the circle and open the Attributes Inspector and add an identifier.
At this point you are done with storyboard now you need to add some code to your view controller to trigger that segue.
let's say that you have a UIImageView then you need to do the following.
- (void)viewDidLoad {
UIImageView *overflow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"my_image.jpg"]];
overflow.frame = CGRectMake(200, 200, 150, 150);
overflow.userInteractionEnabled = true;
[self.view addSubview:overflow];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tap.numberOfTapsRequired = 1;
[overflow addGestureRecognizer:tap];
}
- (void)handleTap:(UITapGestureRecognizer *)recognizer {
[self performSegueWithIdentifier:#"segue_identifier" sender:self];
}
Now every time you want to present the viewController just tap the image
Once the destinationViewController is presented you can dismiss it with
[self dismissViewControllerAnimated:YES completion:nil];
When you right click on the viewController and the menu pops up look below Triggered Segues if manual is empty means that you haven't set a manual segue
Good Luck!
My app is navigated by a slide out menu from the left. On top of each viewController is a left UIBarButton titled "Navigation", that when touched, opens the slide out menu without having to do the drag effect. I am implementing speech commands into my app, and if a user speaks "Go to Finances", it segues to a viewController titled FianceViewController through instantiateViewController to pushViewController.
This all works fine, the only problem is the back button associated with push segue covers up my "Navigation" button in the left slot of the UINavigationBar. Using self.navigationItem.hidesBackButton = YES; hides both the back button and my "Navigation" button. Is there anyway not make a back button appear when the push happens, but still allow my previously created "Navigation" bar button to be seen and used? Or is there another type of segue that I can do other than push if this UIBarButton dilemma cannot be solved?
Section of code that segues when spoken:
if ([title isEqualToString:#"FINANCES"])
{
FinanceViewController *fvc = [[self storyboard] instantiateViewControllerWithIdentifier:#"finance"];
[[self navigationController] pushViewController:fvc animated:YES];
}
How are you adding the navigation button?
I would try to add it after hiding the back button, something like this:
self.navigationItem.hidesBackButton = YES;
UIButton *navigationButton = [[UIButton alloc] initWithFrame:CGRectMake(15.0, 15.0, 100.0, 32.0)];
self.navigationController.navigationBar.backItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:navigationButton];
Instead of hiding my back button, I figured out I could simply write over it! Using fvc.navigationItem.leftBarButtonItem = self.navigationItem.leftBarButtonItem; before pushViewController, allows the "navigation" button to override the back button.
I have a problem with hiding UITabBar. I have a custom tabBar which I hide using:
self.frame = CGRectOffset(tabBarRect, 0, CGRectGetHeight(tabBarRect));
Instead of tabBar, I want to show toolBar. Everything looks fine, but I noticed the area that was previously occupied by tabBar is not responsive, although I offset the tabBar frame.
So, I just put toolBar as a subview of tabBar:
toolBar.frame = CGRectMake(0, CGRectGetHeight(tbv.frame) - toolBar.intrinsicContentSize.height, CGRectGetWidth(self.view.frame), toolBar.intrinsicContentSize.height);
[tbv addSubview:toolBar];
Unfortunately, my tabBar is bigger than toolBar, so I can't use this solution.
I know that I could add toolBar to appDelegate's keyWindow and on top of tabBar, but I'd like to place it within my viewController.
Is there any way to disable tabBar and use toolBar or any other control with gestures within current viewController that is part of navigation based app with tabBar?
Thank yee
may you can try self.hidesBottomBarWhenPushed =YES;
like this:
self.hidesBottomBarWhenPushed =YES;//hide controller's tabbar
UIViewController *controller =[self.storyboard instantiateViewControllerWithIdentifier:#"MyRequirementParticipateInViewController"];
[self.navigationController pushViewController:controller animated:YES];
self.hidesBottomBarWhenPushed =NO;//when pushed back tabbar would show again.
This may not be possible, but I'm hoping someone will have an idea how to do it.
I have an app I'm porting from iPhone only to Universal. On the iPhone, I'm using a Tabbed application. I use three tabs for the normal data to be displayed. I have a forth tab that's only displayed if certain conditions are met. To add the tab, I do:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
UITabBarController *tabController = (UITabBarController *) self.rootViewController;
NSMutableArray* newArray = [NSMutableArray arrayWithArray: tabController.viewControllers];
[newArray addObject: [theStoryboard instantiateViewControllerWithIdentifier: #"AdditionalView-Phone"]];
[tabController setViewControllers:newArray animated:YES];
}
For the iPad, I have enough space on the initial view to display everything from the main three tabs in the iPhone UI. So all I need is one additional (small) view for the "Additional" data. I wanted to do it using a popOver view, so I set up the initial view with a Nav bar and popover button as in the Utility App template. But now I'm stuck. I can't figure out how to create that popover button at run time and make it do the segue to the popOver view properly. I can add the button like this:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] initWithTitle: #"Modem" style: UIBarButtonItemStylePlain target: self action: #selector(togglePopover:)];
self.navBar.topItem.rightBarButtonItem = flipButton;
but I get an exception: 'NSInternalInconsistencyException', reason: 'UIStoryboardPopoverSegue must be presented from a bar button item or a view.' I'm pretty sure this is because I don't have an anchor set for the popOver segue. The button doesn't exist in the storyboard, so I can't set it there. And I can't seem to find an API to set it at run time.
I also tried creating the button in IB, but not in the view hierarchy, and then just setting the rightBarButtonItem property to my existing button. That also works, but I still can't set that button as the anchor for the popover view. I can set the Navigation Bar as the anchor, but that makes it anchor to the title in the nav bar, which looks silly.
Any ideas?
I had the same problem and solved it by creating a UIBarButtonItem in the Storyboard for the view controller but not part of the view hierarchy.
In IB, Drag a bar button item to the dark bar below the view controller view, drop it next to the "First Responder" and "View Controller" icons. Create a (strong) IBOutlet for it. Then create a popover segue from it to the destination view controller by dragging from the bar button item to the destination. It seems like this is the only way to set it as the anchor. Choosing it as the anchor for an existing segue does not work (looks like an IB bug).
In viewDidLoad you can assign this bar button item to the navigationItem (or where ever you like) and the segue works as expected.
I was curious about this too so I made a quick test project. You're right, there doesn't seem to be a way to configure the popover segue at runtime or add an anchor point to a button that's not in the view hierarchy using Interface Builder.
My solution was to set everything up in IB with the UIBarButtonItem visible and connected to an IBOutlet property, then remove it from the navigation bar in -viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = nil;
}
Then I simply add it back or remove it by tapping another button:
- (IBAction)toggleBarButtonItem:(id)sender
{
UIBarButtonItem *item = (self.navigationItem.rightBarButtonItem == nil) ? self.popoverBarButtonItem : nil;
[self.navigationItem setRightBarButtonItem:item animated:YES];
}
You could conditionally keep or remove the button in -viewDidLoad the same way. The segue remains anchored to the UIBarButtonItem.
I'm gonna try making a dummy view that's the size and shape of the views I want to present the popover from, wire that to the segue popover target, and then move the view to the right position in prepareForSegue:sender:
I'm not sure this is exactly what you want, but this is what I would do. Create a button and set it up with some target/action. Call that target/action method
presentPopover:(UIButton *)sender;
Then in the presentPopover method, say
UIViewController *customAdditionalViewController = [[MySpecialVC alloc] init];
//Configure the customAdditionalViewController
//Present the customAdditionalViewController in a Popover
UIPopoverController *popover = [[UIPopoverController alloc] initWithViewController:customAdditionalViewController];
//Set popover configurations
[popover presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:/*whatever you want*/ animated:YES];
That is how I would handle your use case.