Using AwesomeMenu with a UITabBarController tabBar - ios

I have been playing around with adding an AwesomeMenu button to my UITabBar. My plan is to have the icons arc above the tab bar with looks pretty cool. I have played with it a bit and have been able to get the icons to display. I to call the menu, I just used the same button that I already had, added an AwesomeMenu behind the tab bar (so the icons bounce up from behind) then hid the Awesome menu. I added an action to my button in the tab bar to simulate a tap on the awesome menu, as well as show the AwesomeMenu, which then shows the buttons perfectly. The problem is that when I try to tap on any of these button, nothing happens. I assume that this is a problem because they are above the UITabBar, but I cannot be sure. I have added a normal AwesomeMenu in the middle of a blank view controller with the same set up as I have on the tab bar (except being on a tab bar and being called by another button) and it works. When I press a button, they work. Based on this, I figure that it is a problem with the buttons being displayed above the UITabBar or maybe simply the way the buttons work. Any help would be very much appreciated!
Here is how I add the button to the UITabBar (pretty standard):
UIImage *storyMenuItemImage = [UIImage imageNamed:#"Selector_Fill.png"];
UIImage *scaledImage = [UIImage imageWithCGImage:[storyMenuItemImage CGImage] scale:(storyMenuItemImage.scale * 2.0) orientation:UIImageOrientationUp];
UIImage *storyMenuItemImagePressed = [UIImage imageNamed:#"Selector_Fill.png"];
UIImage *starImage = [UIImage imageNamed:#"Selector_Camera_Fill"];
AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Camera_Fill"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Video_Fill"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem3 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Pen"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem4 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem5 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Music_Fill"]
highlightedContentImage:nil];
// the start item, similar to "add" button of Path
AwesomeMenuItem *startItem = [[AwesomeMenuItem alloc] initWithImage:[UIImage imageNamed:#"bg-addbutton.png"]
highlightedImage:[UIImage imageNamed:#"bg-addbutton-highlighted.png"]
ContentImage:[UIImage imageNamed:#"icon-plus.png"]
highlightedContentImage:[UIImage imageNamed:#"icon-plus-highlighted.png"]];
startItem.center = CGPointMake(self.tabBarController.tabBar.center.x , 30);
//22
self.menu = [[AwesomeMenu alloc] initWithFrame:CGRectMake(0, 0, 320, 568) startItem:startItem optionMenus:[NSArray arrayWithObjects:starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5,nil]];
self.menu.startPoint = CGPointMake(160.0, 22.0);
self.menu.rotateAngle = M_PI / 180 * -60;
self.menu.menuWholeAngle = M_PI / 180 * 120;
self.menu.timeOffset = 0.036f;
self.menu.farRadius = 140.0f;
self.menu.nearRadius = 110.0f;
self.menu.endRadius = 120.0f;
self.menu.delegate = self;
self.menu.hidden = YES;
[self.tabBarController.tabBar addSubview:self.menu];
[self.tabBarController.tabBar sendSubviewToBack:self.menu];
Here is how I call it from the button in the UITabBar:
[self.menu touchesBegan:nil withEvent:nil];

You have to add a UIButton into the Tabbar which triggers to initialize an empty view containing all the AwesomeMenu stuff. You can pass the touch event from the button to the awesome menu with - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event. Don't forget to dismiss the ViewController when -(void)awesomeMenuDidFinishAnimationClose:(AwesomeMenu *)menu. You also have to pass the selected MenuItems though a delegate to the parent vc.

Related

Issue with BaTabBarController cocoapod controller (objective-c)

I need to hide previews image, how can i fix it?
https://i.stack.imgur.com/sjlvD.gif
//create inner tab bar item
self.innerTabBarItem = [[UIButton alloc] init];
[self addSubview:self.innerTabBarItem];
self.innerTabBarItem.userInteractionEnabled = NO;//allows for clicks to pass through to the button below
self.innerTabBarItem.translatesAutoresizingMaskIntoConstraints = NO;
//create selected icon
self.selectedImageView = [[UIImageView alloc] initWithImage:selectedImage];
self.selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.selectedImageView];
//create unselected icon
self.unselectedImageView = [[UIImageView alloc] initWithImage:unselectedImage];
self.unselectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.unselectedImageView];

Custom cell with three buttons (with icon) in objective c

I was using PSButtonCell's for links but three individual ones took up too much space so I'm trying to create a custom cell with three buttons in one row; basically like 3 floating icons.
I've got some code for creating a tableview with icons, but currently I do not know how to space them properly (all the icons currently overlap), and I have no idea how I should go about adding tap listeners to the views. Does this look like something I could modify to do what I want? If not does anyone have a better solution they could provide for me? thanks a lot heres my code for the icons
- (id)tableView:(id)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 1) {
UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {320, kHeaderHeight}}];
headerView.backgroundColor = UIColor.clearColor;
headerView.clipsToBounds = YES;
// icon
UIImage *bugicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Bug.png", kSelfBundlePath]];
UIImageView *bugiconView = [[UIImageView alloc] initWithImage:bugicon];
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
// bugiconView.center = (CGPoint){headerView.center.x, bugiconView.center.y};
bugiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:bugiconView];
UIImage *payicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Paypal.png", kSelfBundlePath]];
UIImageView *payiconView = [[UIImageView alloc] initWithImage:payicon];
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
// payiconView.center = (CGPoint){headerView.center.x, payiconView.center.y};
payiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:payiconView];
UIImage *btcicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/bitcoin.png", kSelfBundlePath]];
UIImageView *btciconView = [[UIImageView alloc] initWithImage:btcicon];
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
// btciconView.center = (CGPoint){headerView.center.x, btciconView.center.y};
btciconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:btciconView];
You're adding all the subview is in same position. All UIView frame start from same 'x' position '0'. You need to change 2nd and 3rd frame x positon . ( Change your CGRect 'X' position) for second and third UIView.
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
Hope it helps...

Image on TabBar Not displaying properly.. shows an extra line on top - UPDATED

I have added an ImageView as a subview of my TabBar (that has three NavigationControllers). When i tap on any of the tabs of the tabBarController, then the Image on the imageView changes accordingly (the image shows that particular tab selected and others unselected).
However, the image always shows an extra line on the tabBar. It looks like it crosses the limit of the tabBar. The dimensions of my image is 320x64 pixels (for non-retina iPhone) and 640x128 pixels (for retina iPhone).
Here's how i am declaring instance var for the image view and the tabBarController.
#interface HomePageViewController ()<UITabBarControllerDelegate>
{
UIImageView* tabBarView;
UITabBarController *tabBarController;
}
-(UITabBarController *) configureTheTabBarControllerWithNavControllerAtIndex:(NSInteger)index
{
UINavigationController *customerCareNavController;
UINavigationController *accAndContactsNavController;
UINavigationController *purchaseOrderNavController;
CustomerCareViewController *custCareVC;
PurchaeOrderViewController *POController;
AccountsAndContactsViewController *accAndContactsController;
custCareVC = [[CustomerCareViewController alloc] initWithNibName:#"CustomerCareViewController_iPhone" bundle:NULL];
POController = [[PurchaeOrderViewController alloc] initWithNibName:#"PurchaeOrderViewController_iPhone" bundle:NULL];
accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:#"AccountsAndContactsViewController_iPhone" bundle:NULL];
customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];
purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];
accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];
switch (index) {
case 0:
tabBarController.selectedIndex = 0;
break;
case 1:
tabBarController.selectedIndex = 1;
break;
case 2:
tabBarController.selectedIndex = 2;
break;
}
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
tabBarController.delegate = self;
[self selectTabBarIndex:index];
[self presentViewController:tabBarController animated:YES completion:NULL];
return tabBarController;
}
-(void)tabBarController:(UITabBarController *)TBController didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexSelected = [[TBController viewControllers] indexOfObject:viewController];
[self selectTabBarIndex:indexSelected];
}
- (void) selectTabBarIndex:(NSInteger)index
{
switch (index)
{
case 0:
tabBarView.image=[UIImage imageNamed:#"tab_myCalendar.png"];
break;
case 1:
tabBarView.image=[UIImage imageNamed:#"tab_myDetails.png"];
break;
case 2:
tabBarView.image=[UIImage imageNamed:#"TabBarItem_PO.png"];
break;
}
}
Please see the screenshot..
Setting the barStyle as black gives me the following result
The line has faded a little, but is still visible..
Hey i tried something and it works
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, 0, 320, tabBarController.tabBar.frame.size.height);
However, the image shows a little stretched..
Write this for no stretching: This will work like a charm..!!
tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubView:tabBarView];
Below code will remove line from tabbar...
if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
tabbarController.tabBar.barStyle=UIBarStyleBlackOpaque;
}
Instead of adding the image in an image view as a subview, add the image as the background image of the tab bar, and make the shadow image be an empty image (the line is the shadow image).
tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tab_mypeople.png"];
tabBarController.tabBar.shadowImage = [UIImage new];
If, for some reason, you still need to use a subview rather then a background image, you can continue to do what you have in your question, but set both the background image and the shadow image to empty images (you can't set a custom shadow image without also setting a custom background image). This will get rid of that shadow image line.
tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
write this in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tab_select_indicator"]];

UISearchBar Refuses to Change Width?

I am adding a UISearchBar to a UINavigation Bar as so (this is a storyboard based app) :
//Setup the search bar.
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 50.0f, 44.0f)];
self.tabBarController.navigationItem.titleView = searchBar;
searchBar.delegate = self;
controller = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];
controller.searchResultsDataSource = self;
controller.searchResultsDelegate = self;
No matter what I set the width and height and position of the search bar to be, it will not change the height / width of the search bar. It is always the same width and height.
Can anyone suggest how to alter ?
I've experienced the same problem one time, and what I did was adding the searchBar into a container View (i've had problems showing the cancel button) and add the container view as a left bar item
- (UIBarButtonItem *)createSearchBarHolder {
UIView *searchBarContainer = [[UIView alloc] initWithFrame:navigationSearchBar.frame];
searchBarContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[searchBarContainer addSubview:navigationSearchBar];
navigationSearchBar.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
UIBarButtonItem *searchBarHolder = [[UIBarButtonItem alloc] initWithCustomView:searchBarContainer];
return searchBarHolder;
}
And in viewDidLoad:
NSArray *leftBarButtons = [[NSArray alloc] initWithObjects:[self createSearchBarHolder], nil];
self.navigationItem.leftBarButtonItems = leftBarButtons;
It's not clear what size you want your search bar to be. If you make it the navigation item's titleView, it will adjust for any buttons on the navigation bar, and adjust on rotation. Is that what you want?
- (void)viewDidLoad {
[super viewDidLoad];
UISearchBar *sb = [[UISearchBar alloc] init];
self.navigationItem.titleView = sb;
}

UITableView Not Scrolling With UISearchBar

What I want to achieve is a UISearchBar that moves up and covers the UINavBar, and contains a cancel button on the right of it. All goes well, until I use the following line of code:
searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
What ends up happening is the UITableView just won't scroll, but everything else functions as expected. If I remove that line, my nav bar is visible, and the search bar just sits below it, also lacking a cancel button.
Any ideas?
The code for drawing the search bar is:
self.navigationItem.title = #"Search";
searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 44.0f)] autorelease];
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBar.keyboardType = UIKeyboardTypeAlphabet;
searchBar.delegate = self;
[searchBar becomeFirstResponder];
tableView.tableHeaderView = searchBar;
tableView.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f);
searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;
searchDC.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
searchDC.searchResultsTableView.scrollEnabled = YES;
overlayView.frame = CGRectMake(0, 50, 320, 480);
[self.view addSubview:overlayView];
[self.view bringSubviewToFront:overlayView];
Not enough information to answer this. You need to show the UIViewController or UINavigation Controller code (both the .h and .m) where you are setting up the UISearchDisplayController.
EDIT:
You're implementing this totally wrongly. Apple has a great example on how to implement this http://developer.apple.com/iphone/library/samplecode/TableSearch/Introduction/Intro.html
From Apple's Documentation,
Delegate for the search display controller (delegate), which responds to events such the starting or ending of a search, and the showing or hiding of the search interface.
Set the delegate to your UITableViewController
searchDC.delegate = self;
Also add the searchDC's searchBar to the tableView's headerView
[self.tableView setTableHeaderView:searchDC.searchBar];

Resources