diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 7a46100..435e2fe 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -628,10 +628,10 @@ 4E0DA1B3F943CB5DD84434E2 /* Classes */ = { isa = PBXGroup; children = ( - 948796D629A2FE463CD40F14 /* TabBarItem.h */, - 6D0486D2A6CC5159ED6C3FA5 /* TabBarItem.m */, 6EBFE41004AD256533049528 /* TabBarPicker.h */, 66C7B75EB841D53F0EC483E0 /* TabBarPicker.m */, + 948796D629A2FE463CD40F14 /* TabBarItem.h */, + 6D0486D2A6CC5159ED6C3FA5 /* TabBarItem.m */, 038E63B1DBCA0584644ED157 /* TabBarPickerSubItemsView.h */, 13660ECE3ACE682AFF3887AC /* TabBarPickerSubItemsView.m */, 489D9E1E1C7A2D5F8BC9F84C /* TabBarSubItem.h */, diff --git a/Example/TabBarPicker/TabBarPickerViewController.m b/Example/TabBarPicker/TabBarPickerViewController.m index 954bf73..6856f57 100644 --- a/Example/TabBarPicker/TabBarPickerViewController.m +++ b/Example/TabBarPicker/TabBarPickerViewController.m @@ -58,11 +58,16 @@ [allergen setImage:[UIImage imageNamed:@"allergen_off"]]; [allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; - tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionBottom]; + TabBarItem *allergen2 = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; + [allergen2 setItemName:@"Allergen"]; + [allergen2 setImage:[UIImage imageNamed:@"allergen_off"]]; + [allergen2 setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; + tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionRight]; + [tabbar setItemSpacing:2]; [tabbar setBackgroundColor:[UIColor whiteColor]]; - [tabbar addItem:allergen]; + [tabbar addItem:allergen2]; } return self; } @@ -74,6 +79,8 @@ [contentView addSubview:tabbar]; self.view = contentView; + + [self.view setNeedsUpdateConstraints]; } - (void)viewDidLoad @@ -82,7 +89,6 @@ //[self.view setBackgroundColor:[UIColor lightGrayColor]]; // Do any additional setup after loading the view, typically from a nib. - [super updateViewConstraints]; } - (void) viewDidAppear:(BOOL)animated { @@ -100,7 +106,9 @@ [allergen setImage:[UIImage imageNamed:@"allergen_off"]]; [allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; - [tabbar addItem:allergen]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [tabbar addItem:allergen]; + }); } - (void)didReceiveMemoryWarning diff --git a/Pod/Classes/TabBarItem.m b/Pod/Classes/TabBarItem.m index 64f3762..9db7723 100644 --- a/Pod/Classes/TabBarItem.m +++ b/Pod/Classes/TabBarItem.m @@ -28,6 +28,7 @@ _orientation = [[UIDevice currentDevice] orientation]; _itemButton = [[UIButton alloc] initForAutoLayout]; + [_itemButton setBackgroundColor:[UIColor whiteColor]]; [self addSubview:_itemButton]; @@ -44,7 +45,8 @@ - (void) layoutSubviews { - [_itemButton autoPinEdgesToSuperviewMargins]; + //[_itemButton autoPinEdgesToSuperviewMargins]; + [_itemButton autoCenterInSuperview]; } diff --git a/Pod/Classes/TabBarPicker.m b/Pod/Classes/TabBarPicker.m index 02bd7c6..3a6c4ab 100644 --- a/Pod/Classes/TabBarPicker.m +++ b/Pod/Classes/TabBarPicker.m @@ -60,13 +60,22 @@ } } - [self setNeedsUpdateConstraints]; + [self updateConstraintsIfNeeded]; return self; } - (void) layoutSubviews { + if ([self.constraints count] > 0) { + + [NSLayoutConstraint deactivateConstraints:self.constraints]; + + for (TabBarItem *item in _tabBarItems) { + [item.constraints autoRemoveConstraints]; + } + } + switch (_position) { case TabBarPickerPositionLeft:{ [self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:20]; @@ -111,6 +120,7 @@ break; case TabBarPickerPositionBottom: default:{ + [self autoPinEdgeToSuperviewMargin:ALEdgeBottom]; [self autoSetDimension:ALDimensionHeight toSize:44]; [self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation]; @@ -118,26 +128,20 @@ [_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0]; - [_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES]; - [[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal]; + + [_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES]; } break; } - [self updateConstraints]; + [self updateConstraintsIfNeeded]; } - (void) setPosition:(TabBarPickerPosition)position { _position = position; if (self.superview) { - [self removeConstraints:self.constraints]; - - for (TabBarItem *item in _tabBarItems) { - [item removeConstraints:item.constraints]; - } - [self layoutSubviews]; } } @@ -145,15 +149,11 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification { //Obtain current device orientation _orientation = [[UIDevice currentDevice] orientation]; - - [self layoutSubviews]; } - (void) addItem:(TabBarItem*) item { if (item && [item isKindOfClass:[TabBarItem class]]) { - NSLog(@"%@",self.constraints); - [_tabBarItems addObject:item]; [item setBackgroundColor:[UIColor lightGrayColor]]; [item setDelegate:self]; @@ -162,11 +162,6 @@ if (self.superview) { - [self removeConstraints:self.constraints]; - for (TabBarItem *item in _tabBarItems) { - [item removeConstraints:item.constraints]; - } - [self layoutSubviews]; } }