Permalink
Browse files

better management, contentview added, many fixes for real reality

  • Loading branch information...
divol committed Sep 21, 2011
1 parent e8d50d4 commit fe90048517d59ae3931be1e8126cb067e615ceef
@@ -10,22 +10,26 @@
#import "InfiniTabBar.h"
@interface InfiniTabBarControler : UIViewController <InfiniTabBarDelegate> {
- InfiniTabBar *tabBar;
-
- NSMutableArray *viewControllers;
- UIViewController *selectedViewController;
+ InfiniTabBar *tabBar; // the tab bar
+ IBOutlet UIView *contentView; // a contentview is needed to avoid mess in real world iApp !
+ NSMutableArray *viewControllers;
+ UIViewController *selectedViewController;
id delegate; //compatbility and future use
- NSArray * customizableViewControllers; // unusedhere added for compatibility with UITabBarController
+ NSArray * customizableViewControllers; // unused here added for compatibility with UITabBarController
UINavigationController *moreNavigationController; // unused here added for compatibility with UITabBarController
NSUInteger selectedIndex; // added for compatibility with UITabBarController
+
+
}
@property (nonatomic, retain) InfiniTabBar *tabBar;
+@property (nonatomic, retain) UIView *contentView;
@property (nonatomic, retain) NSMutableArray *viewControllers;
@property (nonatomic, retain) UIViewController *selectedViewController;
@property (nonatomic, assign) id delegate;
@property(nonatomic,copy) NSArray * customizableViewControllers;
@property(nonatomic,readonly) UINavigationController *moreNavigationController;
@property(nonatomic) NSUInteger selectedIndex;
+
- (void)setViewControllers:(NSArray *)aviewControllers animated:(BOOL)animated;
@end
@@ -11,12 +11,14 @@
@implementation InfiniTabBarControler
@synthesize tabBar;
+@synthesize contentView;
@synthesize viewControllers;
@synthesize selectedViewController;
@synthesize delegate;
@synthesize customizableViewControllers;
@synthesize moreNavigationController;
@synthesize selectedIndex;
+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -47,24 +49,26 @@ - (void)didReceiveMemoryWarning
#pragma mark - View lifecycle
/*
-// Implement loadView to create a view hierarchy programmatically, without using a nib.
-- (void)loadView
-{
-}
-*/
+ // Implement loadView to create a view hierarchy programmatically, without using a nib.
+ - (void)loadView
+ {
+ }
+ */
+
-
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.tabBar)
- self.tabBar = [[InfiniTabBar alloc] initWithFrame:self.view.frame];
+ self.tabBar = [[InfiniTabBar alloc] initWithFrame:self.view.frame];
+
// Don't show scroll indicator
self.tabBar.showsHorizontalScrollIndicator = NO;
self.tabBar.infiniTabBarDelegate = self;
self.tabBar.bounces = YES;
[self.view addSubview:self.tabBar];
+ [self.view bringSubviewToFront:self.tabBar];
}
@@ -93,23 +97,30 @@ - (void)setViewControllers:(NSArray *)aviewControllers animated:(BOOL)animated{
unsigned int compteur=0;
NSMutableArray *marray = [[[NSMutableArray alloc] init] autorelease];
for ( UIViewController *ctrl in aviewControllers){
- ctrl.view.frame = CGRectMake(0, 0, sbounds.size.width, sbounds.size.height- 49.0); // leave place to tabbar
+ if (!self.contentView)
+ ctrl.view.frame = CGRectMake(0, 0, sbounds.size.width, sbounds.size.height- 49.0); // leave place to tabbar
if (self.tabBar.tabBars.count ==0){
- ctrl.tabBarItem.tag=compteur;
- [marray addObject:ctrl.tabBarItem];
- compteur++;
+ ctrl.tabBarItem.tag=compteur;
+ [marray addObject:ctrl.tabBarItem];
+ compteur++;
}
}
- if (self.tabBar.tabBars.count ==0){
- [self.tabBar setItems:[NSArray arrayWithArray:marray] animated:YES];
- }
+ if (self.tabBar.tabBars.count ==0){
+ [self.tabBar setItems:[NSArray arrayWithArray:marray] animated:YES];
+ }
- self.viewControllers=[NSMutableArray arrayWithArray:aviewControllers]; // add the view controlers
+ self.viewControllers=[NSMutableArray arrayWithArray:aviewControllers]; // add the view controlers
self.selectedViewController = [self.viewControllers objectAtIndex:0];
[self.tabBar positionArrowAnimated:YES];
- [self.view addSubview:self.selectedViewController.view];
- [self.view bringSubviewToFront:self.selectedViewController.view];
- [self.view bringSubviewToFront:self.tabBar];
+ if (!self.contentView){
+ [self.view addSubview:self.selectedViewController.view];
+ [self.view bringSubviewToFront:self.selectedViewController.view];
+
+ }else{
+ [self.contentView addSubview:self.selectedViewController.view];
+ [self.contentView bringSubviewToFront:self.selectedViewController.view];
+ }
+
}
#pragma mark delegate
@@ -125,27 +136,29 @@ - (BOOL)infiniTabBar:(InfiniTabBar *)tabBar willSelectItemWithTag:(int)tag {
- (void)infiniTabBar:(InfiniTabBar *)tabBar didSelectItemWithTag:(int)tag {
if (self.viewControllers){
if (self.selectedViewController){
-
if (self.selectedViewController.modalViewController){
[self.tabBar positionArrowAnimated:YES];
return;
}
-
[self.selectedViewController.view removeFromSuperview];
self.selectedViewController=nil;
}
if (tag < self.viewControllers.count){
-
+
self.selectedViewController = [self.viewControllers objectAtIndex:tag];
- [self.view addSubview:self.selectedViewController.view];
- [self.view bringSubviewToFront:self.selectedViewController.view];
- }
+ if (!self.contentView){
+ [self.view addSubview:self.selectedViewController.view];
+ [self.view bringSubviewToFront:self.selectedViewController.view];
+
+ }else{
+ [self.contentView addSubview:self.selectedViewController.view];
+ [self.contentView bringSubviewToFront:self.selectedViewController.view];
+ } }
}
+ //nop
self.selectedIndex = tag;
- //nop
- [self.view bringSubviewToFront:self.tabBar];
}
View
@@ -34,6 +34,7 @@
- (BOOL)scrollToTabBarWithTag:(int)tag animated:(BOOL)animated;
- (BOOL)selectItemWithTag:(int)tag;
- (void)positionArrowAnimated:(BOOL)animated;
+
@end
@protocol InfiniTabBarDelegate <NSObject>
View
@@ -41,7 +41,7 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
CGContextAddLineToPoint(ctx,size.width,size.height/2.0);
CGContextAddLineToPoint(ctx,0.0,0.0);
CGContextClosePath(ctx);
-
+
break;
case 4:
//up
@@ -59,7 +59,7 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
CGContextAddLineToPoint(ctx,size.width,size.height);
CGContextAddLineToPoint(ctx,size.width,0.0);
CGContextClosePath(ctx);
-
+
break;
}
@@ -74,9 +74,9 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
UIGraphicsEndImageContext();
return result;
-
-
+
+
}
- (void)didMoveToSuperview{
[super didMoveToSuperview];
@@ -144,7 +144,7 @@ -(void)arrowDecoration{
}
}
-
+
}
@@ -166,7 +166,7 @@ - (id)initWithFrame:(CGRect)frame{
float x = 0.0;
-
+
self.contentSize = CGSizeMake(x, 49.0);
@@ -191,10 +191,10 @@ - (id)initWithFrameAndItems:(CGRect)frame items:(NSArray *)items {
if (self) {
[self setItems:items animated:NO];
-
-
+
+
}
-
+
return self;
}
@@ -219,15 +219,15 @@ - (void)positionArrowAnimated:(BOOL)animated {
UIScreen *screen = [UIScreen mainScreen];
CGRect sbounds = screen.applicationFrame;
-
+
int nbitems = tb.items.count;
float pos = (tag % 5) * ((sbounds.size.width/nbitems));
f.origin.x = pos + (((sbounds.size.width/nbitems) / 2) - (f.size.width / 2));
f.origin.y= sbounds.size.height- 55;
-
- self.arrow.frame = f;
+
+ self.arrow.frame = f;
if (animated) {
[UIView commitAnimations];
}
@@ -261,8 +261,8 @@ - (void)setBounces:(BOOL)bounces {
- (void)setItems:(NSArray *)items animated:(BOOL)animated {
- if (self.tabBars.count !=0){
-
+ if (self.tabBars.count !=0){
+
for (UITabBar *tabBar in self.tabBars) {
int len = 0;
@@ -275,39 +275,39 @@ - (void)setItems:(NSArray *)items animated:(BOOL)animated {
self.contentSize = CGSizeMake(ceil(items.count / 5.0) * self.frame.size.width, 49.0);
-
- }else{
- UIScreen *screen = [UIScreen mainScreen];
- CGRect sbounds = screen.applicationFrame;
-
- float x = 0.0;
-
- for (double d = 0; d < ceil(items.count / 5.0); d ++) {
- UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(x, 0.0, sbounds.size.width, 49.0)];
- tabBar.delegate = self;
-
- int len = 0;
-
- for (int i = d * 5; i < d * 5 + 5; i ++)
- if (i < items.count)
- len ++;
-
- tabBar.items = [items objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(d * 5, len)]];
-
- [self addSubview:tabBar];
-
- [self.tabBars addObject:tabBar];
-
- [tabBar release];
-
- x += self.frame.size.width;
- }
-
- self.contentSize = CGSizeMake(x, 49.0);
-
- }
- [self positionArrowAnimated:animated];
- [self arrowDecoration];
+
+ }else{
+ UIScreen *screen = [UIScreen mainScreen];
+ CGRect sbounds = screen.applicationFrame;
+
+ float x = 0.0;
+
+ for (double d = 0; d < ceil(items.count / 5.0); d ++) {
+ UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(x, 0.0, sbounds.size.width, 49.0)];
+ tabBar.delegate = self;
+
+ int len = 0;
+
+ for (int i = d * 5; i < d * 5 + 5; i ++)
+ if (i < items.count)
+ len ++;
+
+ tabBar.items = [items objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(d * 5, len)]];
+
+ [self addSubview:tabBar];
+
+ [self.tabBars addObject:tabBar];
+
+ [tabBar release];
+
+ x += self.frame.size.width;
+ }
+
+ self.contentSize = CGSizeMake(x, 49.0);
+
+ }
+ [self positionArrowAnimated:animated];
+ [self arrowDecoration];
}
- (int)currentTabBarTag {
@@ -356,7 +356,7 @@ - (BOOL)selectItemWithTag:(int)tag {
- (void)layoutSubviews {
[super layoutSubviews];
-
+
[self positionArrowAnimated:NO];
}
@@ -372,6 +372,7 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
}
- (void)tabBar:(UITabBar *)cTabBar didSelectItem:(UITabBarItem *)item {
+
if ([infiniTabBarDelegate infiniTabBar:self willSelectItemWithTag:item.tag]){
// Act like a single tab bar
for (UITabBar *tabBar in self.tabBars)
@@ -395,8 +396,8 @@ - (void)dealloc {
[imageviewleft release];
if (imageviewright)
[imageviewright release];
-
-
+
+
[super dealloc];
}
Oops, something went wrong.

0 comments on commit fe90048

Please sign in to comment.