Bottom half of UITabbar is not responding to clicks - objective-c

I have created a UITabbar with 3 items and placed it on a UIScrollView
When I click the buttons of the tabbar they do not respond in the bottom half.
The upper area is working fine.
When clicking in the area just above the tabbar the tabs are also switched.
What can be wrong?
How can i correct this misalignment of the clickable button area?
In viewDidLoad:
[super viewDidLoad];
scroll.frame = CGRectMake(0, 20, 320, 460);
scroll.pagingEnabled = YES;
scroll.contentSize = CGSizeMake(320 * 2, 460);
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.delegate = self;
scroll.pagingEnabled = YES;
viewNavController1 = [[viewNavController1 alloc] init];
ctrl = [[UITabBarController alloc] init];
ViewController1 *viewC1= [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UINavigationController *control = [[UINavigationController alloc] initWithRootViewController:viewC1];
viewC1.title = #"Title1";
[viewC1 release];
ViewController2 *viewC2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
UINavigationController *control2 = [[UINavigationController alloc] initWithRootViewController:viewC2];
viewC2.title = #"Title2";
[viewC2 release];
UINavigationController *control3 = [[UINavigationController alloc] init];
ViewController3 *viewC3 = [[ViewController3 alloc] initWithNibName:#"ViewController3" bundle:nil];
[control3 pushViewController:viewC3 animated:NO];
viewC3.title = #"Title3";
[viewC3 release];
[ctrl setViewControllers:[NSArray arrayWithObjects:control,control2,control3,nil]];
CGRect frame = scroll.frame;
frame.origin.x = frame.size.width * 0;
frame.origin.y = 0;
viewNavController1.view.frame = frame;
viewC4 = [[ViewController4 alloc] initWithNibName:#"ViewController4" bundle:nil];
[viewNavController1 pushViewController:viewC4 animated:NO];
[scroll addSubview:viewNavController1.view];
frame = scroll.frame;
frame.origin.x = frame.size.width * 1;
frame.origin.y = 0;
ctrl.view.frame = frame;
[scroll addSubview:ctrl.view];
[scroll scrollRectToVisible:CGRectMake(320, 0, 320, 460) animated:NO];
UITabBarItem *itm = [ctrl.tabBar.items objectAtIndex:0];
itm.image = [UIImage imageNamed:#"img1.png"];
itm = [ctrl.tabBar.items objectAtIndex:1];
itm.image = [UIImage imageNamed:#"img2.png"];
itm = [ctrl.tabBar.items objectAtIndex:2];
itm.image = [UIImage imageNamed:#"img3.png"];
[control release];
[control2 release];
[control3 release];

The problem was that the UITabbarController did not have its view added as the root view of the windows. Which it apparently assumes.
so I had to trick it using:
[vc setWantsFullScreenLayout:YES];
vc is the main ViewController holding the scrollview containing the UITabbarController.
See Offset on UIWindow addSubview for more explanations.

Related

TabBar with center button

Hi, I'd like to make a tabBar with center button. As we can see from the image, when I clicked the tabbar, it will show me a view to select buttons. When I clicked the "notes" button, the view will disappear and my app will jump to the correspond viewcontroller and the tabbar.selectIndex = 2. I already made a subclass of UITabBarController, and add a button to the view, the code is like this [self.view addSubview:middleButton]. Now the problem is, when I push viewcontroll, the tabbar disappear while the center button still on the page. And when I go back to the main viewcontroller, the tabbar will overlap the center button. I don't want to make a whole custom UITabBarViewController, please tell me how to hide the center button when push viewcontroll and how to show it on the tapbar when I go back to the main viewcontroller.
Hi, Hament, I have not use method "-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item". My code is as below:
#implementation MyTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupViews];
[self setupTabBarItems];
[self setupMiddleButton];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setupViews
{
mask = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([MyMiddleButtonMask class]) owner:self options:nil].firstObject;
mask.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
mask.delegate = self;
}
-(void)setupTabBarItems
{
UIViewController *vc1 = [[UIViewController alloc] init];
vc1Nav = [[UINavigationController alloc] initWithRootViewController:vc1];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2Nav = [[UINavigationController alloc] initWithRootViewController:vc2];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3Nav = [[UINavigationController alloc] initWithRootViewController:vc3];
UIViewController *vc6 = [[UIViewController alloc] init];
vc6Nav = [[UINavigationController alloc] initWithRootViewController:vc6];
UIViewController *vc7 = [[UIViewController alloc] init];
vc7Nav = [[UINavigationController alloc] initWithRootViewController:vc7];
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
}
-(void)setupMiddleButton
{
middleButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -16, 64, 64)];
CGRect f = middleButton.frame;
f.origin.y = SCREEN_HEIGHT - f.size.height;
f.origin.x = (SCREEN_WIDTH - f.size.width)/2;
middleButton.frame = f;
[middleButton setImage:[UIImage imageNamed:#"plus"] forState:UIControlStateNormal];
middleButton.backgroundColor = [UIColor redColor];
middleButton.layer.cornerRadius = middleButton.frame.size.height/2;
[self.view addSubview:middleButton];
[middleButton addTarget:self action:#selector(didClickedMiddleButton:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)didClickedMiddleButton:(id)sender
{
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:mask];
}
#pragma mark - KGOMiddleButtonMaskDelegate, Button1,2,3 are on the mask page.
-(void)didClickedButton1:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc3Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton2:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc4Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedButton3:(KGOMiddleButtonMask *)maskView
{
self.viewControllers = #[vc1Nav, vc2Nav, vc5Nav, vc6Nav, vc7Nav];
self.selectedIndex = 2;
[maskView removeFromSuperview];
}
-(void)didClickedSelf:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}
-(void)didClickedCloseButton:(KGOMiddleButtonMask *)maskView
{
[maskView removeFromSuperview];
}

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

iOS8 popovercontroller height issue

I have a UIPopovercontroller.
Presenting it using this way.
BackupPop *backupPop = [[BackupPop alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
backupPop.delegate = self;
backupPop.navigationItem.title = [Language get2:#"Backup"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:backupPop];
assigningBackupRow = button.tag;
backupPopController = [[UIPopoverController alloc] initWithContentViewController:navController];
backupPopController.popoverContentSize = CGSizeMake(200, 150);
CGRect rect = CGRectMake(button.frame.origin.x, button.frame.origin.y + 20 + (button.tag - 30000) * 44, button.frame.size.width, button.frame.size.height);
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
In the UIPopovercontroller, I have a UITableView in viewdidload.
funcTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 80) style:UITableViewStylePlain];
[funcTable setDelegate:self];
[funcTable setDataSource:self];
[funcTable setRowHeight:44];
[funcTable setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:funcTable];
The problem in iOS8, although my UITableView is 80px in height, it shows up as 40px only.
The starting position of the UITableView is right, but the height is not. Now, I have to put 120px as height to all of the UITableView that is in UIPopoverController. No such issue in iOS7.
Guys, any idea? Thanks.
Try this
iOS 8 has new PopOverController called UIPopoverPresentationController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:#"Terms_NC"];
navController.preferredContentSize = CGSizeMake(300, 290);
// Present the view controller using the popover style.
navController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[navController popoverPresentationController];
presentationController.permittedArrowDirections =0;
presentationController.sourceView = self.view;
presentationController.sourceRect = CGRectMake(100, 100, 300, 340);
i had the same problem. what i did was i explicitly set the size of tableview again just before i was presenting my popover.
[backupPop adjustFrame];
backupPopController.popoverContentSize = backupPop.view.frame.size;
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
and you can add a method in backupPop
- (void)adjustFrame {
CGRect frame = self.view.frame;
frame.size.height = 80
frame.size.width = 200;
self.view.frame = frame;
}
Lemme know if it helps.
May be its workaround set the content size after little delay.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.popoverController setPopoverContentSize:CGSizeMake(300, 340) animated:YES];
});

equivalent [UIPopoverController setContentViewController:(UIViewController *) animated:(BOOL)]; for iOS8

what's the proper way to set UIPopoverController size in iOS8
in iOS7 was
[UIPopoverController setContentViewController:(UIViewController *) animated:(BOOL)];
but now it doesn't work
thanks in advance
EDIT: Gonna put my piece of code here and both results (iOS7.1 and iOS8)
DetalleTarjetaVC *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"DetalleTarjetaVC"];
UINavigationController *navController;
navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.toolbarHidden = FALSE;
navController.navigationBar.translucent = FALSE;
navController.toolbar.translucent = FALSE;
navController.navigationBar.barTintColor = UIColorFromRGBWithAlpha(toolbarTintColor, 0.95);
navController.navigationBar.barStyle = UIBarStyleBlack;
navController.toolbar.barTintColor = UIColorFromRGBWithAlpha(toolbarTintColor, 0.95);
navController.toolbar.barStyle = UIBarStyleBlack;
controller.view.backgroundColor = UIColorFromRGBWithAlpha(0XFFFFFF, 1);
tarjetasPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
CGRect rect = button.frame;
CGPoint coord = [button convertPoint:button.frame.origin toView:self.tableView];
rect.origin.y = coord.y -20;
[tarjetasPopover setPopoverContentSize:CGSizeMake(530, 400) animated:YES];
[tarjetasPopover presentPopoverFromRect:rect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
there's something that may help you
int iOSVersion = [[[UIDevice currentDevice]systemVersion] intValue];
if (iOSVersion >= 8) {
controller.preferredContentSize = CGSizeMake(530, 312);
}
else{
[tarjetasPopover setPopoverContentSize:CGSizeMake(530, 400) animated:YES];
}
I reduced in 88.0 height for iOS8 since you have to consider the width of your toolbar and navigation controller (44px each) for getting same size
The method have not been replaced in iOS8. You just need to alloc an istance before, like that:
UIPopoverController *yourPopoverController = [[UIPopoverController alloc] init];
and then you can use:
[yourPopoverController setContentViewController:yourViewController animated:YES];
Or easily you can pass the viewController on UIPopoverController Init:
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:yourViewController];
Hope it help.

How can I create unique PopoverView

How can I create special popOver?
I have manually created a new class, with needed design.
Then I want to load it like a PopOver
-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];
myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
But when I trying to tap the button, my app crashes with exc_bad_access
What`s wrong?
Use this code to create the popover
-(IBAction)Click_event
{ UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
{
Popview *pop = [[Popview alloc] initWithNibName:#"Popview" bundle:nil];
popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
[popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[popoverview dismissPopoverAnimated:YES];
}
}
Lets try this. It may be helpful for you
Try this way u may fix the issue....
PopimagepickerViewController.h
UIPopoverController *popoverController;
UIPopoverController *popoverimagview; // imagepicker popoverview
PopimagepickerViewController.m
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // Set the popoverview Width and height
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft //pooverview down direction
animated:YES];
[popoverView release];
[popoverContent release];
}
Your code seems overly complex, and non standard. I use this code to create a popover.
(I've edited this to match your case, but it's not tested)
-(void) buttonAction:(id) sender
{
UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[myThirdPop release];
}