diff --git a/samples/TTCatalog/Classes/PhotoTest1Controller.m b/samples/TTCatalog/Classes/PhotoTest1Controller.m index 93a452d590..a08e3f489c 100644 --- a/samples/TTCatalog/Classes/PhotoTest1Controller.m +++ b/samples/TTCatalog/Classes/PhotoTest1Controller.m @@ -36,7 +36,7 @@ - (void)viewDidLoad { caption:@"These are the wood tiles that we had installed after the accident."] autorelease], // Causes album to be loaded -// [NSNull null], + // [NSNull null], [[[MockPhoto alloc] initWithURL:@"http://farm2.static.flickr.com/1124/3164979509_bcfdd72123.jpg?v=0" diff --git a/src/TTPhotoViewController.m b/src/TTPhotoViewController.m index 19265b6303..3b0fcf79fa 100644 --- a/src/TTPhotoViewController.m +++ b/src/TTPhotoViewController.m @@ -39,6 +39,9 @@ - (id)init { self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle: TTLocalizedString(@"Photo", @"Title for back button that returns to photo browser") style:UIBarButtonItemStylePlain target:nil action:nil] autorelease]; + self.navigationBarStyle = UIBarStyleBlackTranslucent; + self.navigationBarTintColor = nil; + self.statusBarStyle = UIStatusBarStyleBlackTranslucent; } return self; } @@ -312,7 +315,7 @@ - (void)hideBarsAnimationDidStop { - (void)loadView { CGRect screenFrame = [UIScreen mainScreen].bounds; self.view = [[[TTUnclippedView alloc] initWithFrame:screenFrame] autorelease]; - + CGRect innerFrame = CGRectMake(0, -CHROME_HEIGHT, screenFrame.size.width, screenFrame.size.height + CHROME_HEIGHT); _innerView = [[UIView alloc] initWithFrame:innerFrame]; @@ -340,18 +343,12 @@ - (void)loadView { _toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, screenFrame.size.height - TOOLBAR_HEIGHT, screenFrame.size.width, TOOLBAR_HEIGHT)]; - _toolbar.barStyle = UIBarStyleBlackTranslucent; + _toolbar.barStyle = self.navigationBarStyle; _toolbar.items = [NSArray arrayWithObjects: space, _previousButton, space, _nextButton, space, nil]; [_innerView addSubview:_toolbar]; } -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - [self changeNavigationBarStyle:UIBarStyleBlackTranslucent barColor:nil - statusBarStyle:UIStatusBarStyleBlackTranslucent]; -} - - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; @@ -377,11 +374,14 @@ - (void)viewWillDisappear:(BOOL)animated { if (self.nextViewController) { [self showBars:YES animated:NO]; } - [self restoreNavigationBarStyle]; } - (void)showBars:(BOOL)show animated:(BOOL)animated { [super showBars:show animated:animated]; + + CGFloat alpha = show ? 1 : 0; + if (alpha == _toolbar.alpha) + return; if (animated) { [UIView beginAnimations:nil context:nil]; @@ -402,7 +402,7 @@ - (void)showBars:(BOOL)show animated:(BOOL)animated { [self showCaptions:show]; - _toolbar.alpha = show ? 1 : 0; + _toolbar.alpha = alpha; if (animated) { [UIView commitAnimations]; diff --git a/src/TTThumbsViewController.m b/src/TTThumbsViewController.m index f4e89a5080..646b391fa7 100644 --- a/src/TTThumbsViewController.m +++ b/src/TTThumbsViewController.m @@ -198,6 +198,9 @@ - (id)init { _photoSource = nil; self.hidesBottomBarWhenPushed = YES; + self.navigationBarStyle = UIBarStyleBlackTranslucent; + self.navigationBarTintColor = nil; + self.statusBarStyle = UIStatusBarStyleBlackTranslucent; } return self; @@ -213,34 +216,36 @@ - (void)dealloc { // UIViewController - (void)loadView { - self.view = [[[TTUnclippedView alloc] initWithFrame:TTApplicationFrame()] autorelease]; - self.view.backgroundColor = [UIColor whiteColor]; + CGRect screenFrame = [UIScreen mainScreen].bounds; + self.view = [[[TTUnclippedView alloc] initWithFrame:screenFrame] autorelease]; self.view.autoresizesSubviews = YES; self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + + CGRect innerFrame = CGRectMake(0, -CHROME_HEIGHT, + screenFrame.size.width, screenFrame.size.height + CHROME_HEIGHT); + UIView* innerView = [[UIView alloc] initWithFrame:innerFrame]; + innerView.backgroundColor = [UIColor whiteColor]; + [self.view addSubview:innerView]; - self.tableView = [[[UITableView alloc] initWithFrame:TTNavigationFrame() + CGRect tableFrame = CGRectMake(0, CHROME_HEIGHT, + screenFrame.size.width, screenFrame.size.height - CHROME_HEIGHT); + self.tableView = [[[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain] autorelease]; self.tableView.rowHeight = kThumbnailRowHeight; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth - | UIViewAutoresizingFlexibleHeight; + | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.separatorColor = [UIColor whiteColor]; self.tableView.contentInset = UIEdgeInsetsMake(4, 0, 0, 0); self.tableView.clipsToBounds = NO; - [self.view addSubview:self.tableView]; -} - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - [self changeNavigationBarStyle:UIBarStyleBlackTranslucent barColor:nil - statusBarStyle:UIStatusBarStyleBlackTranslucent]; + [innerView addSubview:self.tableView]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self suspendLoadingThumbnails:NO]; - if (animated && !self.nextViewController) { + if (!self.nextViewController) { self.view.superview.frame = CGRectOffset(self.view.superview.frame, 0, TOOLBAR_HEIGHT); } } @@ -248,11 +253,7 @@ - (void)viewDidAppear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - if (animated) { - self.view.superview.frame = CGRectOffset(self.view.superview.frame, 0, TOOLBAR_HEIGHT); - } - - [self restoreNavigationBarStyle]; + self.view.superview.frame = CGRectOffset(self.view.superview.frame, 0, TOOLBAR_HEIGHT); } - (void)viewDidDisappear:(BOOL)animated { diff --git a/src/TTUnclippedView.m b/src/TTUnclippedView.m index bb6b06005c..fce8f163f7 100644 --- a/src/TTUnclippedView.m +++ b/src/TTUnclippedView.m @@ -6,8 +6,12 @@ - (void)didMoveToSuperview { for (UIView* p = self; p; p = p.superview) { // This allows the view to be shown "full screen", and not offset by the toolbar and status bar p.clipsToBounds = NO; - p.backgroundColor = self.backgroundColor; + //p.backgroundColor = self.backgroundColor; } } +- (void)setFrame:(CGRect)rect { + [super setFrame:rect]; +} + @end diff --git a/src/TTViewController.m b/src/TTViewController.m index fa34c04e1b..783340c57d 100644 --- a/src/TTViewController.m +++ b/src/TTViewController.m @@ -1,49 +1,21 @@ #import "Three20/TTViewController.h" #import "Three20/TTErrorView.h" #import "Three20/TTURLRequestQueue.h" +#import "Three20/TTStyleSheet.h" /////////////////////////////////////////////////////////////////////////////////////////////////// @implementation TTViewController @synthesize frozenState = _frozenState, viewState = _viewState, - contentError = _contentError, appearing = _appearing, appeared = _appeared, + contentError = _contentError, navigationBarStyle = _navigationBarStyle, + navigationBarTintColor = _navigationBarTintColor, statusBarStyle = _statusBarStyle, + appearing = _appearing, appeared = _appeared, autoresizesForKeyboard = _autoresizesForKeyboard; /////////////////////////////////////////////////////////////////////////////////////////////////// // private -//- (void)changeStyleFrom:(TTViewControllerStyle)from { -// if (from != style) { -// UINavigationBar* bar = self.navigationController.navigationBar; -// if (style == TTViewControllerStyleTranslucent) { -// bar.tintColor = nil; -// bar.barStyle = UIBarStyleBlackTranslucent; -// [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent -// animated:YES]; -// } else { -// bar.tintColor = [TTResources facebookDarkBlue]; -// bar.barStyle = UIBarStyleDefault; -// [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault -// animated:YES]; -// } -// } -//} -// -//- (void)updateStyle { -// TTViewController* topController = (TTViewController*)self.navigationController.topViewController; -// if (topController != self) { -// [self changeStyleFrom:topController.style]; -// } else { -// NSArray* controllers = self.navigationController.viewControllers; -// if (controllers.count > 1) { -// TTViewController* backController = [controllers objectAtIndex:controllers.count-2]; -// [self changeStyleFrom:backController.style]; -// } -// } -// [topController release]; -//} - - (BOOL)resizeForKeyboard:(NSNotification*)notification { NSValue* v1 = [notification.userInfo objectForKey:UIKeyboardBoundsUserInfoKey]; CGRect keyboardBounds; @@ -87,10 +59,9 @@ - (id)init { _frozenState = nil; _viewState = TTViewEmpty; _contentError = nil; - _previousBar = nil; - _previousBarStyle = 0; - _previousBarTintColor = nil; - _previousStatusBarStyle = 0; + _navigationBarStyle = UIBarStyleDefault; + _navigationBarTintColor = nil; + _statusBarStyle = UIStatusBarStyleDefault; _invalidView = YES; _invalidViewLoading = NO; _invalidViewData = YES; @@ -99,6 +70,8 @@ - (id)init { _appeared = NO; _unloaded = NO; _autoresizesForKeyboard = NO; + + self.navigationBarTintColor = TTSTYLEVAR(navigationBarTintColor); } return self; } @@ -114,8 +87,7 @@ - (void)dealloc { [[TTURLRequestQueue mainQueue] cancelRequestsWithDelegate:self]; - [_previousBar release]; - [_previousBarTintColor release]; + [_navigationBarTintColor release]; [_frozenState release]; [_contentError release]; [self unloadView]; @@ -152,6 +124,12 @@ - (void)viewWillAppear:(BOOL)animated { [self validateView]; [TTURLRequestQueue mainQueue].suspended = YES; + + UINavigationBar* bar = self.navigationController.navigationBar; + bar.tintColor = _navigationBarTintColor; + bar.barStyle = _navigationBarStyle; + + [[UIApplication sharedApplication] setStatusBarStyle:_statusBarStyle animated:YES]; } - (void)viewDidAppear:(BOOL)animated { @@ -162,10 +140,6 @@ - (void)viewWillDisappear:(BOOL)animated { _appearing = NO; } -//- (void)viewDidDisappear:(BOOL)animated { -// _appearing = NO; -//} - - (void)didReceiveMemoryWarning { TTLOG(@"MEMORY WARNING FOR %@", self); @@ -274,7 +248,7 @@ - (void)invalidateViewState:(TTViewState)state { _invalidViewLoading = (_viewState & TTViewLoadingStates) != (state & TTViewLoadingStates); } if (!_invalidViewData) { - _invalidViewData = state == TTViewDataLoaded + _invalidViewData = state == TTViewDataLoaded || state == TTViewEmpty || (_viewState & TTViewDataStates) != (state & TTViewDataStates); } @@ -369,45 +343,4 @@ - (NSString*)subtitleForError:(NSError*)error { return TTLocalizedString(@"Sorry, an error has occurred.", @""); } -- (void)changeNavigationBarStyle:(UIBarStyle)barStyle barColor:(UIColor*)barColor - statusBarStyle:(UIStatusBarStyle)statusBarStyle { - if (!_previousBar) { - UINavigationBar* bar = self.navigationController.navigationBar; - if (!self.nextViewController) { - [_previousBar release]; - [_previousBarTintColor release]; - _previousBar = [bar retain]; - _previousBarStyle = bar.barStyle; - _previousBarTintColor = [bar.tintColor retain]; - _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; - } - - bar.tintColor = barColor; - bar.barStyle = barStyle; - - [[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle animated:YES]; - } -} - -- (void)restoreNavigationBarStyle { - // If we're going backwards... - if (!self.nextViewController && _previousBar) { - _previousBar.tintColor = _previousBarTintColor; - _previousBar.barStyle = _previousBarStyle; - - UIApplication* app = [UIApplication sharedApplication]; - if (app.statusBarHidden) { - app.statusBarStyle = _previousStatusBarStyle; - [app setStatusBarHidden:NO animated:YES]; - } else { - [app setStatusBarStyle:_previousStatusBarStyle animated:YES]; - } - - [_previousBarTintColor release]; - _previousBarTintColor = nil; - [_previousBar release]; - _previousBar = nil; - } -} - @end diff --git a/src/Three20/TTViewController.h b/src/Three20/TTViewController.h index 1f8e22db42..b8e2878ae9 100644 --- a/src/Three20/TTViewController.h +++ b/src/Three20/TTViewController.h @@ -18,10 +18,9 @@ typedef enum { TTViewState _viewState; NSError* _contentError; - UINavigationBar* _previousBar; - UIBarStyle _previousBarStyle; - UIColor* _previousBarTintColor; - UIStatusBarStyle _previousStatusBarStyle; + UIBarStyle _navigationBarStyle; + UIColor* _navigationBarTintColor; + UIStatusBarStyle _statusBarStyle; BOOL _invalidView; BOOL _invalidViewLoading; @@ -58,6 +57,21 @@ typedef enum { */ @property(nonatomic, retain) NSError* contentError; +/** + * The style of the navigation bar when this controller is pushed onto a navigation controller. + */ +@property(nonatomic) UIBarStyle navigationBarStyle; + +/** + * The color of the navigation bar when this controller is pushed onto a navigation controller. + */ +@property(nonatomic,retain) UIColor* navigationBarTintColor; + +/** + * The style of the status bar when this controller is appearing. + */ +@property(nonatomic) UIStatusBarStyle statusBarStyle; + /** * The view has appeared at least once. */ @@ -201,15 +215,4 @@ typedef enum { */ - (NSString*)subtitleForError:(NSError*)error; -/** - * - */ -- (void)changeNavigationBarStyle:(UIBarStyle)barStyle barColor:(UIColor*)barColor - statusBarStyle:(UIStatusBarStyle)statusBarStyle; - -/** - * - */ -- (void)restoreNavigationBarStyle; - @end diff --git a/src/UIViewControllerAdditions.m b/src/UIViewControllerAdditions.m index 95d81d020f..fb7fa6f27d 100644 --- a/src/UIViewControllerAdditions.m +++ b/src/UIViewControllerAdditions.m @@ -81,11 +81,11 @@ - (void)pushViewController:(UIViewController*)controller [self pushViewController:controller animated:NO]; - [UIView beginAnimations:nil context:NULL]; + [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)]; - [UIView setAnimationTransition:transition forView:self.view.window cache:YES]; + [UIView setAnimationTransition:transition forView:self.view cache:YES]; [UIView commitAnimations]; } @@ -98,7 +98,7 @@ - (void)popViewControllerAnimatedWithTransition:(UIViewAnimationTransition)trans [UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)]; - [UIView setAnimationTransition:transition forView:self.view.window cache:YES]; + [UIView setAnimationTransition:transition forView:self.view cache:YES]; [UIView commitAnimations]; }