Browse files

added methods to show/hide bottom bar when pushing/popping a vc, plus…

… some spinny utils
  • Loading branch information...
1 parent 489dc7f commit 4024ce9588f51a1cdef3f69f0acd8d71cf2c0a80 @ettore committed Oct 20, 2011
Showing with 117 additions and 0 deletions.
  1. +50 −0 clcg_gfx.h
  2. +67 −0 clcg_gfx.m
View
50 clcg_gfx.h
@@ -35,3 +35,53 @@
* Does a snapshot of a view appending a title below it.
*/
UIImage *clcg_do_snapshot(UIView *v, NSString *title);
+
+
+/**
+ * Scenario: you want to hide the bottom bar when a VC of class 'hiding_vc_class'
+ * is pushed on the stack.
+ *
+ * Usage: from your UINavigationController subclass, override
+ * pushViewController:animated: and call this function before calling super.
+ * Use this function in conjunction with poppingVCFromHiding().
+ *
+ * @param nc The Navigation Controller who's pushing the view controllers on
+ * the navigation stack.
+ * @param vc The view conroller about to be pushed.
+ * @param hiding_vc_class The specific class for which we want to hide the
+ * bottom bar.
+ */
+void pushingVCForHiding(UINavigationController *nc,
+ UIViewController *vc,
+ Class hiding_vc_class);
+
+
+/**
+ * Scenario: you want to show back the bottom bar when a VC of class
+ * 'hiding_vc_class' is popped from the stack.
+ *
+ * Usage: from your UINavigationController subclass, override
+ * popViewControllerAnimated: and call this function before calling super.
+ *
+ * @param nc The Navigation Controller who's popping the view controllers on
+ * the navigation stack.
+ * @param hiding_vc_class The specific class for which we want to hide the
+ * bottom bar.
+ */
+void poppingVCFromHiding(UINavigationController *nc, Class hiding_vc_class);
+
+
+/**
+ * Creates an UIActivityIndicatorView of given size in pixels and returns it.
+ * The returned instance is not autoreleased: the celler will have to
+ * take care of releasing it when needed.
+ */
+UIActivityIndicatorView *newSpinny(CGFloat size);
+
+
+/**
+ * Creates an UIActivityIndicatorView of given size in pixels, attaches it to
+ * the accessory view of the table-view cell, and autoreleases it.
+ */
+void attachSpinnyToCell(CGFloat size, UITableViewCell *cell);
+
View
67 clcg_gfx.m
@@ -32,6 +32,7 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#import <QuartzCore/QuartzCore.h>
#import "clcg_gfx.h"
+
//TODO-XX make font name and height parameters
UIImage *clcg_do_snapshot(UIView *v, NSString *title)
{
@@ -66,3 +67,69 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
return snapshot;
}
+
+
+void pushingVCForHiding(UINavigationController *nc,
+ UIViewController *vc,
+ Class hiding_vc_class)
+{
+ BOOL is_board_ctrl = [vc isKindOfClass:hiding_vc_class];
+
+ vc.hidesBottomBarWhenPushed = is_board_ctrl;
+
+ // controller currently displayed, about to be be superseded
+ UIViewController *curr = [nc topViewController];
+ if (!is_board_ctrl)
+ curr.hidesBottomBarWhenPushed = NO;
+}
+
+
+void poppingVCFromHiding(UINavigationController *nc, Class hiding_vc_class)
+{
+ // this is the controller about to be removed
+ //UIViewController *curr = [nc topViewController];
+
+ NSArray *vcs = [nc viewControllers];
+ int cnt = [vcs count];
+ if (cnt >= 2) {
+ UIViewController *prev = [vcs objectAtIndex:cnt-2];
+ if ([prev isKindOfClass:hiding_vc_class]) {
+ prev.hidesBottomBarWhenPushed = YES;
+ }
+ }
+
+ // now this would be the controller about to be displayed
+ // curr = [nc topViewController];
+}
+
+
+// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+#pragma mark - Spinny
+
+UIActivityIndicatorView *newSpinny(CGFloat size)
+{
+ CGRect f;
+ UIActivityIndicatorView *spinny;
+
+ f = CGRectMake(0.0, 0.0, size, size);
+ spinny = [[UIActivityIndicatorView alloc] initWithFrame:f];
+ [spinny startAnimating];
+ [spinny setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
+ [spinny sizeToFit];
+ [spinny setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin |
+ UIViewAutoresizingFlexibleRightMargin |
+ UIViewAutoresizingFlexibleTopMargin |
+ UIViewAutoresizingFlexibleBottomMargin)];
+ return spinny;
+}
+
+
+void attachSpinnyToCell(CGFloat size, UITableViewCell *cell)
+{
+ UIActivityIndicatorView *spinny;
+
+ spinny = newSpinny(size);
+ [cell setAccessoryView:spinny];
+ [spinny release];
+}
+

0 comments on commit 4024ce9

Please sign in to comment.