Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

better management, contentview added, many fixes for real reality

  • Loading branch information...
commit fe90048517d59ae3931be1e8126cb067e615ceef 1 parent e8d50d4
divol authored September 21, 2011
14  Classes/InfiniTabBarControler.h
@@ -10,16 +10,19 @@
10 10
 #import "InfiniTabBar.h"
11 11
 
12 12
 @interface InfiniTabBarControler : UIViewController <InfiniTabBarDelegate> {
13  
-    InfiniTabBar *tabBar;
14  
-    
15  
-     NSMutableArray         *viewControllers;
16  
-     UIViewController       *selectedViewController;
  13
+    InfiniTabBar *tabBar; // the tab bar
  14
+    IBOutlet UIView *contentView; // a contentview is needed to avoid mess in real world iApp !
  15
+    NSMutableArray         *viewControllers;
  16
+    UIViewController       *selectedViewController;
17 17
     id                      delegate; //compatbility and future use
18  
-    NSArray                * customizableViewControllers; // unusedhere added for compatibility with UITabBarController
  18
+    NSArray                * customizableViewControllers; // unused here added for compatibility with UITabBarController
19 19
     UINavigationController *moreNavigationController; // unused here added for compatibility with UITabBarController
20 20
     NSUInteger selectedIndex; // added for compatibility with UITabBarController
  21
+    
  22
+    
21 23
 }
22 24
 @property (nonatomic, retain) InfiniTabBar *tabBar;
  25
+@property (nonatomic, retain) UIView *contentView;
23 26
 @property (nonatomic, retain) NSMutableArray *viewControllers;
24 27
 @property (nonatomic, retain) UIViewController       *selectedViewController;
25 28
 @property (nonatomic, assign) id delegate;
@@ -27,5 +30,6 @@
27 30
 @property(nonatomic,readonly) UINavigationController *moreNavigationController;
28 31
 @property(nonatomic) NSUInteger selectedIndex;
29 32
 
  33
+
30 34
 - (void)setViewControllers:(NSArray *)aviewControllers animated:(BOOL)animated;
31 35
 @end
65  Classes/InfiniTabBarControler.m
@@ -11,12 +11,14 @@
11 11
 
12 12
 @implementation InfiniTabBarControler
13 13
 @synthesize tabBar;
  14
+@synthesize contentView;
14 15
 @synthesize viewControllers;
15 16
 @synthesize selectedViewController;
16 17
 @synthesize delegate;
17 18
 @synthesize customizableViewControllers;
18 19
 @synthesize moreNavigationController;
19 20
 @synthesize selectedIndex;
  21
+
20 22
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
21 23
 {
22 24
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -47,24 +49,26 @@ - (void)didReceiveMemoryWarning
47 49
 #pragma mark - View lifecycle
48 50
 
49 51
 /*
50  
-// Implement loadView to create a view hierarchy programmatically, without using a nib.
51  
-- (void)loadView
52  
-{
53  
-}
54  
-*/
  52
+ // Implement loadView to create a view hierarchy programmatically, without using a nib.
  53
+ - (void)loadView
  54
+ {
  55
+ }
  56
+ */
  57
+
55 58
 
56  
- 
57 59
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
58 60
 - (void)viewDidLoad
59 61
 {
60 62
     [super viewDidLoad];
61 63
     if (!self.tabBar)
62  
-     self.tabBar = [[InfiniTabBar alloc] initWithFrame:self.view.frame];
  64
+        self.tabBar = [[InfiniTabBar alloc] initWithFrame:self.view.frame];
  65
+    
63 66
     // Don't show scroll indicator
64 67
 	self.tabBar.showsHorizontalScrollIndicator = NO;
65 68
 	self.tabBar.infiniTabBarDelegate = self;
66 69
 	self.tabBar.bounces = YES;
67 70
     [self.view addSubview:self.tabBar];
  71
+    [self.view bringSubviewToFront:self.tabBar]; 
68 72
 }
69 73
 
70 74
 
@@ -93,23 +97,30 @@ - (void)setViewControllers:(NSArray *)aviewControllers animated:(BOOL)animated{
93 97
     unsigned int compteur=0;
94 98
     NSMutableArray *marray = [[[NSMutableArray alloc] init] autorelease];
95 99
     for ( UIViewController *ctrl in aviewControllers){
96  
-        ctrl.view.frame = CGRectMake(0, 0, sbounds.size.width, sbounds.size.height- 49.0); // leave place to tabbar
  100
+        if (!self.contentView)
  101
+             ctrl.view.frame = CGRectMake(0, 0, sbounds.size.width, sbounds.size.height- 49.0); // leave place to tabbar
97 102
         if (self.tabBar.tabBars.count ==0){
98  
-             ctrl.tabBarItem.tag=compteur;
99  
-             [marray addObject:ctrl.tabBarItem];
100  
-             compteur++;
  103
+            ctrl.tabBarItem.tag=compteur;
  104
+            [marray addObject:ctrl.tabBarItem];
  105
+            compteur++;
101 106
         }
102 107
     }
103  
-     if (self.tabBar.tabBars.count ==0){
104  
-         [self.tabBar setItems:[NSArray arrayWithArray:marray] animated:YES];
105  
-     }
  108
+    if (self.tabBar.tabBars.count ==0){
  109
+        [self.tabBar setItems:[NSArray arrayWithArray:marray] animated:YES];
  110
+    }
106 111
     
107  
-        self.viewControllers=[NSMutableArray arrayWithArray:aviewControllers]; // add the view controlers
  112
+    self.viewControllers=[NSMutableArray arrayWithArray:aviewControllers]; // add the view controlers
108 113
     self.selectedViewController = [self.viewControllers objectAtIndex:0];
109 114
     [self.tabBar positionArrowAnimated:YES];
110  
-    [self.view addSubview:self.selectedViewController.view];
111  
-    [self.view bringSubviewToFront:self.selectedViewController.view]; 
112  
-    [self.view bringSubviewToFront:self.tabBar]; 
  115
+	if (!self.contentView){
  116
+        [self.view addSubview:self.selectedViewController.view];
  117
+        [self.view bringSubviewToFront:self.selectedViewController.view];
  118
+
  119
+    }else{
  120
+        [self.contentView addSubview:self.selectedViewController.view];
  121
+        [self.contentView bringSubviewToFront:self.selectedViewController.view];
  122
+    }
  123
+    
113 124
 }
114 125
 
115 126
 #pragma mark delegate
@@ -125,27 +136,29 @@ - (BOOL)infiniTabBar:(InfiniTabBar *)tabBar willSelectItemWithTag:(int)tag {
125 136
 - (void)infiniTabBar:(InfiniTabBar *)tabBar didSelectItemWithTag:(int)tag {
126 137
     if (self.viewControllers){
127 138
         if (self.selectedViewController){
128  
-            
129 139
             if (self.selectedViewController.modalViewController){
130 140
                 [self.tabBar positionArrowAnimated:YES];
131 141
                 return;
132 142
             }
133  
-            
134 143
             [self.selectedViewController.view removeFromSuperview]; 
135 144
             self.selectedViewController=nil;
136 145
             
137 146
         }
138 147
         if (tag < self.viewControllers.count){
139  
-           
  148
+            
140 149
             self.selectedViewController = [self.viewControllers objectAtIndex:tag];
141 150
             
142  
-           [self.view addSubview:self.selectedViewController.view];
143  
-            [self.view bringSubviewToFront:self.selectedViewController.view]; 
144  
-        }
  151
+            if (!self.contentView){
  152
+                [self.view addSubview:self.selectedViewController.view];
  153
+                [self.view bringSubviewToFront:self.selectedViewController.view];
  154
+                
  155
+            }else{
  156
+                [self.contentView addSubview:self.selectedViewController.view];
  157
+                [self.contentView bringSubviewToFront:self.selectedViewController.view];
  158
+            }        }
145 159
     }
  160
+    //nop
146 161
     self.selectedIndex  = tag;
147  
-      //nop
148  
-    [self.view bringSubviewToFront:self.tabBar];
149 162
 }
150 163
 
151 164
 
1  InfiniTabBar.h
@@ -34,6 +34,7 @@
34 34
 - (BOOL)scrollToTabBarWithTag:(int)tag animated:(BOOL)animated;
35 35
 - (BOOL)selectItemWithTag:(int)tag;
36 36
 - (void)positionArrowAnimated:(BOOL)animated;
  37
+
37 38
 @end
38 39
 
39 40
 @protocol InfiniTabBarDelegate <NSObject>
101  InfiniTabBar.m
@@ -41,7 +41,7 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
41 41
             CGContextAddLineToPoint(ctx,size.width,size.height/2.0);
42 42
             CGContextAddLineToPoint(ctx,0.0,0.0);
43 43
             CGContextClosePath(ctx);
44  
-
  44
+            
45 45
             break;
46 46
         case 4:
47 47
             //up
@@ -59,7 +59,7 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
59 59
             CGContextAddLineToPoint(ctx,size.width,size.height);
60 60
             CGContextAddLineToPoint(ctx,size.width,0.0);
61 61
             CGContextClosePath(ctx);
62  
-
  62
+            
63 63
             break;
64 64
             
65 65
     }
@@ -74,9 +74,9 @@ -(UIImage*)makeTriangle:(CGRect)rect where:(int)where{
74 74
 	UIGraphicsEndImageContext();
75 75
     
76 76
     return result;
77  
-
78 77
     
79  
-
  78
+    
  79
+    
80 80
 }
81 81
 - (void)didMoveToSuperview{
82 82
     [super didMoveToSuperview];
@@ -144,7 +144,7 @@ -(void)arrowDecoration{
144 144
         }
145 145
         
146 146
     }
147  
-
  147
+    
148 148
 }
149 149
 
150 150
 
@@ -166,7 +166,7 @@ - (id)initWithFrame:(CGRect)frame{
166 166
 		
167 167
 		float x = 0.0;
168 168
 		
169  
-				
  169
+        
170 170
 		self.contentSize = CGSizeMake(x, 49.0);
171 171
         
172 172
         
@@ -191,10 +191,10 @@ - (id)initWithFrameAndItems:(CGRect)frame items:(NSArray *)items {
191 191
 	
192 192
     if (self) {
193 193
 		[self setItems:items animated:NO];
194  
-                
195  
-
  194
+        
  195
+        
196 196
 	}
197  
-	 
  197
+    
198 198
     return self;
199 199
 }
200 200
 
@@ -219,15 +219,15 @@ - (void)positionArrowAnimated:(BOOL)animated {
219 219
         
220 220
         UIScreen *screen = [UIScreen mainScreen];
221 221
         CGRect sbounds = screen.applicationFrame;
222  
-
  222
+        
223 223
         int nbitems = tb.items.count;
224 224
         
225 225
         float pos = (tag % 5) * ((sbounds.size.width/nbitems));
226 226
         
227 227
         f.origin.x = pos + (((sbounds.size.width/nbitems) / 2) - (f.size.width / 2));
228 228
         f.origin.y= sbounds.size.height- 55;  
229  
-         
230  
-         self.arrow.frame = f;
  229
+        
  230
+        self.arrow.frame = f;
231 231
         if (animated) {
232 232
             [UIView commitAnimations];
233 233
         }
@@ -261,8 +261,8 @@ - (void)setBounces:(BOOL)bounces {
261 261
 
262 262
 - (void)setItems:(NSArray *)items animated:(BOOL)animated {
263 263
     
264  
-     if (self.tabBars.count !=0){
265  
-         
  264
+    if (self.tabBars.count !=0){
  265
+        
266 266
         for (UITabBar *tabBar in self.tabBars) {
267 267
             
268 268
             int len = 0;
@@ -275,39 +275,39 @@ - (void)setItems:(NSArray *)items animated:(BOOL)animated {
275 275
         
276 276
         self.contentSize = CGSizeMake(ceil(items.count / 5.0) * self.frame.size.width, 49.0);
277 277
         
278  
-       
279  
-     }else{
280  
-         UIScreen *screen = [UIScreen mainScreen];
281  
-         CGRect sbounds = screen.applicationFrame;
282  
-         
283  
-         float x = 0.0;
284  
-         
285  
-         for (double d = 0; d < ceil(items.count / 5.0); d ++) {
286  
-             UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(x, 0.0, sbounds.size.width, 49.0)];
287  
-             tabBar.delegate = self;
288  
-             
289  
-             int len = 0;
290  
-             
291  
-             for (int i = d * 5; i < d * 5 + 5; i ++)
292  
-                 if (i < items.count)
293  
-                     len ++;
294  
-             
295  
-             tabBar.items = [items objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(d * 5, len)]];
296  
-             
297  
-             [self addSubview:tabBar];
298  
-             
299  
-             [self.tabBars addObject:tabBar];
300  
-             
301  
-             [tabBar release];
302  
-             
303  
-             x += self.frame.size.width;
304  
-         }
305  
-         
306  
-         self.contentSize = CGSizeMake(x, 49.0);
307  
-         
308  
-     }
309  
-     [self positionArrowAnimated:animated];
310  
-     [self arrowDecoration];
  278
+        
  279
+    }else{
  280
+        UIScreen *screen = [UIScreen mainScreen];
  281
+        CGRect sbounds = screen.applicationFrame;
  282
+        
  283
+        float x = 0.0;
  284
+        
  285
+        for (double d = 0; d < ceil(items.count / 5.0); d ++) {
  286
+            UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(x, 0.0, sbounds.size.width, 49.0)];
  287
+            tabBar.delegate = self;
  288
+            
  289
+            int len = 0;
  290
+            
  291
+            for (int i = d * 5; i < d * 5 + 5; i ++)
  292
+                if (i < items.count)
  293
+                    len ++;
  294
+            
  295
+            tabBar.items = [items objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(d * 5, len)]];
  296
+            
  297
+            [self addSubview:tabBar];
  298
+            
  299
+            [self.tabBars addObject:tabBar];
  300
+            
  301
+            [tabBar release];
  302
+            
  303
+            x += self.frame.size.width;
  304
+        }
  305
+        
  306
+        self.contentSize = CGSizeMake(x, 49.0);
  307
+        
  308
+    }
  309
+    [self positionArrowAnimated:animated];
  310
+    [self arrowDecoration];
311 311
 }
312 312
 
313 313
 - (int)currentTabBarTag {
@@ -356,7 +356,7 @@ - (BOOL)selectItemWithTag:(int)tag {
356 356
 
357 357
 - (void)layoutSubviews {
358 358
 	[super layoutSubviews];
359  
-		
  359
+    
360 360
 	[self positionArrowAnimated:NO];
361 361
 }
362 362
 
@@ -372,6 +372,7 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
372 372
 }
373 373
 
374 374
 - (void)tabBar:(UITabBar *)cTabBar didSelectItem:(UITabBarItem *)item {
  375
+    
375 376
     if ([infiniTabBarDelegate infiniTabBar:self willSelectItemWithTag:item.tag]){
376 377
         // Act like a single tab bar
377 378
         for (UITabBar *tabBar in self.tabBars)
@@ -395,8 +396,8 @@ - (void)dealloc {
395 396
         [imageviewleft release];
396 397
     if (imageviewright)
397 398
         [imageviewright release];
398  
-
399  
-
  399
+    
  400
+    
400 401
 	[super dealloc];
401 402
 }
402 403
 
20,256  InfiniTabBar.xcodeproj/project.xcworkspace/xcuserdata/divol.xcuserdatad/UserInterfaceState.xcuserstate
13187 additions, 7069 deletions not shown
16  InfiniTabBar.xcodeproj/xcuserdata/divol.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -2,20 +2,4 @@
2 2
 <Bucket
3 3
    type = "1"
4 4
    version = "1.0">
5  
-   <FileBreakpoints>
6  
-      <FileBreakpoint
7  
-         shouldBeEnabled = "Yes"
8  
-         ignoreCount = "0"
9  
-         continueAfterRunningActions = "No"
10  
-         isPathRelative = "1"
11  
-         filePath = "Classes/InfiniTabBarControler.m"
12  
-         timestampString = "338205592.247437"
13  
-         startingColumnNumber = "9223372036854775807"
14  
-         endingColumnNumber = "9223372036854775807"
15  
-         startingLineNumber = "25"
16  
-         endingLineNumber = "25"
17  
-         landmarkName = "-initWithNibName:bundle:"
18  
-         landmarkType = "5">
19  
-      </FileBreakpoint>
20  
-   </FileBreakpoints>
21 5
 </Bucket>

0 notes on commit fe90048

Please sign in to comment.
Something went wrong with that request. Please try again.