From b77b68c3f2c3d96507e4d2f57a836cb738e35a8c Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 01:32:59 -0800 Subject: [PATCH 01/10] Adding TUINavigationController. --- TwUI.xcodeproj/project.pbxproj | 10 +- lib/UIKit/TUIKit.h | 1 + lib/UIKit/TUINavigationController.h | 28 +++++ lib/UIKit/TUINavigationController.m | 156 ++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 lib/UIKit/TUINavigationController.h create mode 100644 lib/UIKit/TUINavigationController.m diff --git a/TwUI.xcodeproj/project.pbxproj b/TwUI.xcodeproj/project.pbxproj index fa8aee44..2b25420c 100755 --- a/TwUI.xcodeproj/project.pbxproj +++ b/TwUI.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 48A10E8415B7769A007F9EE3 /* TUILayoutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 48A10E8015B7769A007F9EE3 /* TUILayoutManager.m */; }; 48A10E8915B778E8007F9EE3 /* TUIView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 48A10E8715B778E8007F9EE3 /* TUIView+Layout.m */; }; 48A10E8B15B77A46007F9EE3 /* TUIView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E8A15B77A46007F9EE3 /* TUIView+Layout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5000874016524B1C0067ED42 /* TUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 5000873F16524B1C0067ED42 /* TUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5000874916524B1F0067ED42 /* TUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5000874816524B1F0067ED42 /* TUINavigationController.m */; }; 5E6ECEB313BE791600109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; }; 5E6ECEB413BE791600109598 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5E31B613BE6F49004B7899 /* QuartzCore.framework */; }; 5E6ECEB613BE791C00109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; }; @@ -436,6 +438,8 @@ 48A10E8015B7769A007F9EE3 /* TUILayoutManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUILayoutManager.m; sourceTree = ""; }; 48A10E8715B778E8007F9EE3 /* TUIView+Layout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIView+Layout.m"; sourceTree = ""; }; 48A10E8A15B77A46007F9EE3 /* TUIView+Layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIView+Layout.h"; sourceTree = ""; }; + 5000873F16524B1C0067ED42 /* TUINavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUINavigationController.h; sourceTree = ""; }; + 5000874816524B1F0067ED42 /* TUINavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUINavigationController.m; sourceTree = ""; }; 5EE9839C13BE7650005F430D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; }; 5EE983B713BE7809005F430D /* libtwui.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libtwui.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8819794213E26E0200AA39EB /* TUIView+Accessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIView+Accessibility.h"; sourceTree = ""; }; @@ -794,6 +798,8 @@ 48A10E7E15B7769A007F9EE3 /* TUILayoutConstraint.m */, 48A10E7F15B7769A007F9EE3 /* TUILayoutManager.h */, 48A10E8015B7769A007F9EE3 /* TUILayoutManager.m */, + 5000873F16524B1C0067ED42 /* TUINavigationController.h */, + 5000874816524B1F0067ED42 /* TUINavigationController.m */, 8819794A13E26E5800AA39EB /* TUINSView+Accessibility.h */, 8819794B13E26E5800AA39EB /* TUINSView+Accessibility.m */, CBB74C5E13BE6E1900C85CB5 /* TUINSView+Hyperfocus.h */, @@ -845,8 +851,8 @@ CBB74C7913BE6E1900C85CB5 /* TUITextRenderer+Event.h */, CBB74C7A13BE6E1900C85CB5 /* TUITextRenderer+Event.m */, CBB74C7B13BE6E1900C85CB5 /* TUITextRenderer+KeyBindings.m */, - CBB74C7C13BE6E1900C85CB5 /* TUITextRenderer.h */, 48373DF4160EAE9400322CA7 /* TUITextRenderer+Private.h */, + CBB74C7C13BE6E1900C85CB5 /* TUITextRenderer.h */, CBB74C7D13BE6E1900C85CB5 /* TUITextRenderer.m */, CBB74C7E13BE6E1900C85CB5 /* TUITextView.h */, CBB74C7F13BE6E1900C85CB5 /* TUITextView.m */, @@ -995,6 +1001,7 @@ D0C7651615B61E5A00E7AC2C /* TUIBridgedScrollView.h in Headers */, D0C7653315B624D900E7AC2C /* NSView+TUIExtensions.h in Headers */, D0C7654615B626E200E7AC2C /* TUIView+TUIBridgedView.h in Headers */, + 5000874016524B1C0067ED42 /* TUINavigationController.h in Headers */, D0C7655215B6294400E7AC2C /* TUIScrollView+TUIBridgedScrollView.h in Headers */, D0C7655D15B6297300E7AC2C /* NSClipView+TUIExtensions.h in Headers */, D0C7656315B6297300E7AC2C /* NSScrollView+TUIExtensions.h in Headers */, @@ -1396,6 +1403,7 @@ 887C227C15C1C7BB006EC31D /* NSFont+TUIExtensions.m in Sources */, D0EA12F415C34FEA00FAA603 /* NSColor+TUIExtensions.m in Sources */, 488A5836162FBE9B006CBF8B /* TUITableViewController.m in Sources */, + 5000874916524B1F0067ED42 /* TUINavigationController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/lib/UIKit/TUIKit.h b/lib/UIKit/TUIKit.h index de578e75..5a64be2e 100644 --- a/lib/UIKit/TUIKit.h +++ b/lib/UIKit/TUIKit.h @@ -33,6 +33,7 @@ #import "TUIImageView.h" #import "TUILabel.h" #import "TUILayoutConstraint.h" +#import "TUINavigationController.h" #import "TUINSView.h" #import "TUINSView+Hyperfocus.h" #import "TUINSView+NSTextInputClient.h" diff --git a/lib/UIKit/TUINavigationController.h b/lib/UIKit/TUINavigationController.h new file mode 100644 index 00000000..7a029980 --- /dev/null +++ b/lib/UIKit/TUINavigationController.h @@ -0,0 +1,28 @@ +// +// TUINavigationController.h +// TwUI +// +// Created by Max Goedjen on 11/12/12. +// +// + +#import +#import "TUIViewController.h" + +@interface TUINavigationController : TUIViewController + +- (id)initWithRootViewController:(TUIViewController *)viewController; + +@property (nonatomic, readonly) TUIViewController *topViewController; + +@property (nonatomic, readonly) NSArray *viewControllers; + +- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated; + +- (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)animated; +- (void)popViewControlerAnimated:(BOOL)animated; +- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; +- (NSArray *)popToViewController:(TUIViewController *)viewController animated:(BOOL)animated; + + +@end diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m new file mode 100644 index 00000000..5f7dd748 --- /dev/null +++ b/lib/UIKit/TUINavigationController.m @@ -0,0 +1,156 @@ + // +// TUINavigationController.m +// TwUI +// +// Created by Max Goedjen on 11/12/12. +// +// + +#import "TUINavigationController.h" +#import "TUIView.h" + +@interface TUINavigationController () + +@property (nonatomic) NSMutableArray *stack; + +@end + +#define kPushPopDuration .5 +#define kPushDelay .1 + +@implementation TUINavigationController + +- (id)initWithRootViewController:(TUIViewController *)viewController { + self = [super init]; + if (self) { + _stack = [@[] mutableCopy]; + [_stack addObject:viewController]; + self.view.clipsToBounds = YES; + } + return self; +} + +- (void)loadView { + self.view = [[TUIView alloc] initWithFrame:CGRectZero]; + self.view.backgroundColor = [NSColor lightGrayColor]; + + TUIViewController *visible = [self topViewController]; + [visible viewWillAppear:NO]; + [self.view addSubview:visible.view]; + visible.view.frame = self.view.bounds; + visible.view.autoresizingMask = TUIViewAutoresizingFlexibleHeight | TUIViewAutoresizingFlexibleWidth; + [visible viewDidAppear:YES]; + +} + +#pragma mark - Properties + +- (NSArray *)viewControllers { + return [NSArray arrayWithArray:_stack]; +} + +- (TUIViewController *)topViewController { + return [_stack lastObject]; +} + +#pragma mark - Methods + +- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { + [_stack removeAllObjects]; + [_stack addObjectsFromArray:viewControllers]; +} + +- (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)animated { + + TUIViewController *last = [self topViewController]; + [_stack addObject:viewController]; + CGFloat duration = animated ? kPushPopDuration : 0; + + [last viewWillDisappear:animated]; + [viewController viewWillAppear:animated]; + + [self.view addSubview:viewController.view]; + + [TUIView animateWithDuration:kPushDelay animations:^{ + //If we assign the frame manually, it 'pops' in + viewController.view.frame = [self _offscreenRightFrame]; + } completion:^(BOOL finished) { + [TUIView animateWithDuration:duration animations:^{ + last.view.frame = [self _offscreenLeftFrame]; + viewController.view.frame = self.view.bounds; + } completion:^(BOOL finished) { + [last.view removeFromSuperview]; + [viewController viewDidAppear:animated]; + [last viewDidDisappear:animated]; + }]; + }]; +} + +- (void)popViewControlerAnimated:(BOOL)animated { + if ([_stack count] <= 1) { + [NSException raise:NSInvalidArgumentException format:@"Stack has one or less view controllers"]; + return; + } + [self popToViewController:[_stack objectAtIndex:([_stack count] - 2)] animated:animated]; +} + +- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated { + if ([[self topViewController] isEqual:[_stack objectAtIndex:0]] == YES) { + return @[]; + } + return [self popToViewController:[_stack objectAtIndex:0] animated:animated]; +} + +- (NSArray *)popToViewController:(TUIViewController *)viewController animated:(BOOL)animated { + if ([_stack containsObject:viewController] == NO) { + [NSException raise:NSInvalidArgumentException format:@"View controller %@ is not in stack", viewController]; + return @[]; + } + + TUIViewController *last = [_stack lastObject]; + + NSMutableArray *popped = [@[] mutableCopy]; + while ([viewController isEqual:[_stack lastObject]] == NO) { + [popped addObject:[_stack lastObject]]; + [_stack removeLastObject]; + } + + + [self.view addSubview:viewController.view]; + viewController.view.frame = [self _offscreenLeftFrame]; + + CGFloat duration = animated ? kPushPopDuration : 0; + + [last viewWillDisappear:animated]; + [viewController viewWillAppear:animated]; + + [TUIView animateWithDuration:duration animations:^{ + last.view.frame = [self _offscreenRightFrame]; + viewController.view.frame = self.view.bounds; + } completion:^(BOOL finished) { + [last.view removeFromSuperview]; + [viewController viewDidAppear:animated]; + [last viewDidDisappear:animated]; + }]; + + + return popped; +} + +#pragma mark - Private + +- (CGRect)_offscreenLeftFrame { + CGRect bounds = self.view.bounds; + CGRect offscreenLeft = bounds; + offscreenLeft.origin.x -= bounds.size.width; + return offscreenLeft; +} + +- (CGRect)_offscreenRightFrame { + CGRect bounds = self.view.bounds; + CGRect offscreenRight = bounds; + offscreenRight.origin.x += bounds.size.width; + return offscreenRight; +} + +@end From 85bcd64c7491dbfc6ea45865aefee27e0fa494a7 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 01:38:42 -0800 Subject: [PATCH 02/10] Less hacky way of making sure pushes don't pop in. --- lib/UIKit/TUINavigationController.m | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 5f7dd748..9a4893eb 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -71,18 +71,19 @@ - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)an [self.view addSubview:viewController.view]; - [TUIView animateWithDuration:kPushDelay animations:^{ - //If we assign the frame manually, it 'pops' in - viewController.view.frame = [self _offscreenRightFrame]; + //Make sure the app draws the frame offscreen instead of just 'popping' it in + [CATransaction begin]; + viewController.view.frame = [self _offscreenRightFrame]; + [CATransaction flush]; + [CATransaction commit]; + + [TUIView animateWithDuration:duration animations:^{ + last.view.frame = [self _offscreenLeftFrame]; + viewController.view.frame = self.view.bounds; } completion:^(BOOL finished) { - [TUIView animateWithDuration:duration animations:^{ - last.view.frame = [self _offscreenLeftFrame]; - viewController.view.frame = self.view.bounds; - } completion:^(BOOL finished) { - [last.view removeFromSuperview]; - [viewController viewDidAppear:animated]; - [last viewDidDisappear:animated]; - }]; + [last.view removeFromSuperview]; + [viewController viewDidAppear:animated]; + [last viewDidDisappear:animated]; }]; } From 11418661f8b5695407f8c5324c68e998384187f1 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 01:49:23 -0800 Subject: [PATCH 03/10] Removed unused constant. --- lib/UIKit/TUINavigationController.m | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 9a4893eb..c18463e9 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -16,7 +16,6 @@ @interface TUINavigationController () @end #define kPushPopDuration .5 -#define kPushDelay .1 @implementation TUINavigationController From b566f85c41f2129e64cd81155d3338bee2fc54c7 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:02:16 -0800 Subject: [PATCH 04/10] Various improvements as suggested by @galaxas0 and @CodaFi --- TwUI.xcodeproj/project.pbxproj | 2 ++ lib/UIKit/TUINavigationController.h | 7 +++---- lib/UIKit/TUINavigationController.m | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/TwUI.xcodeproj/project.pbxproj b/TwUI.xcodeproj/project.pbxproj index 2b25420c..dcbb2437 100755 --- a/TwUI.xcodeproj/project.pbxproj +++ b/TwUI.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 48A10E8B15B77A46007F9EE3 /* TUIView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E8A15B77A46007F9EE3 /* TUIView+Layout.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5000874016524B1C0067ED42 /* TUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 5000873F16524B1C0067ED42 /* TUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5000874916524B1F0067ED42 /* TUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5000874816524B1F0067ED42 /* TUINavigationController.m */; }; + 5000874A1652C4380067ED42 /* TUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5000874816524B1F0067ED42 /* TUINavigationController.m */; }; 5E6ECEB313BE791600109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; }; 5E6ECEB413BE791600109598 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5E31B613BE6F49004B7899 /* QuartzCore.framework */; }; 5E6ECEB613BE791C00109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; }; @@ -1329,6 +1330,7 @@ D05D23A515BF7239000ED14F /* NSImage+TUIExtensions.m in Sources */, D0EA12F615C34FEA00FAA603 /* NSColor+TUIExtensions.m in Sources */, 488A5838162FBE9B006CBF8B /* TUITableViewController.m in Sources */, + 5000874A1652C4380067ED42 /* TUINavigationController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/lib/UIKit/TUINavigationController.h b/lib/UIKit/TUINavigationController.h index 7a029980..77373243 100644 --- a/lib/UIKit/TUINavigationController.h +++ b/lib/UIKit/TUINavigationController.h @@ -11,16 +11,15 @@ @interface TUINavigationController : TUIViewController -- (id)initWithRootViewController:(TUIViewController *)viewController; - @property (nonatomic, readonly) TUIViewController *topViewController; - @property (nonatomic, readonly) NSArray *viewControllers; +- (id)initWithRootViewController:(TUIViewController *)viewController; + - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated; - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)animated; -- (void)popViewControlerAnimated:(BOOL)animated; +- (TUIViewController *)popViewControlerAnimated:(BOOL)animated; - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(BOOL)animated; diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index c18463e9..c96a012b 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -15,7 +15,7 @@ @interface TUINavigationController () @end -#define kPushPopDuration .5 +static CGFloat const TUINavigationControllerAnimationDuration = 0.5f; @implementation TUINavigationController @@ -37,7 +37,7 @@ - (void)loadView { [visible viewWillAppear:NO]; [self.view addSubview:visible.view]; visible.view.frame = self.view.bounds; - visible.view.autoresizingMask = TUIViewAutoresizingFlexibleHeight | TUIViewAutoresizingFlexibleWidth; + visible.view.autoresizingMask = TUIViewAutoresizingFlexibleSize; [visible viewDidAppear:YES]; } @@ -63,7 +63,7 @@ - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)an TUIViewController *last = [self topViewController]; [_stack addObject:viewController]; - CGFloat duration = animated ? kPushPopDuration : 0; + CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; [last viewWillDisappear:animated]; [viewController viewWillAppear:animated]; @@ -86,10 +86,10 @@ - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)an }]; } -- (void)popViewControlerAnimated:(BOOL)animated { +- (TUIViewController *)popViewControlerAnimated:(BOOL)animated { if ([_stack count] <= 1) { - [NSException raise:NSInvalidArgumentException format:@"Stack has one or less view controllers"]; - return; + NSLog(@"Not enough view controllers on stack to pop"); + return @[]; } [self popToViewController:[_stack objectAtIndex:([_stack count] - 2)] animated:animated]; } @@ -119,7 +119,7 @@ - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(B [self.view addSubview:viewController.view]; viewController.view.frame = [self _offscreenLeftFrame]; - CGFloat duration = animated ? kPushPopDuration : 0; + CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; [last viewWillDisappear:animated]; [viewController viewWillAppear:animated]; From 9ffacfb7cb9ec42e6c2c74b655a029714ec14655 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:03:32 -0800 Subject: [PATCH 05/10] Fixed return type on popViewContorllerAniamted: --- lib/UIKit/TUINavigationController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index c96a012b..9c1ceb82 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -89,9 +89,11 @@ - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)an - (TUIViewController *)popViewControlerAnimated:(BOOL)animated { if ([_stack count] <= 1) { NSLog(@"Not enough view controllers on stack to pop"); - return @[]; + return nil; } + TUIViewController *popped = [_stack lastObject]; [self popToViewController:[_stack objectAtIndex:([_stack count] - 2)] animated:animated]; + return popped; } - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated { From 542c6693d401233ba8b033ae37af95a729b3861d Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:09:44 -0800 Subject: [PATCH 06/10] Removed exception in favor of log --- lib/UIKit/TUINavigationController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 9c1ceb82..20d3d9e0 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -105,7 +105,7 @@ - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated { - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(BOOL)animated { if ([_stack containsObject:viewController] == NO) { - [NSException raise:NSInvalidArgumentException format:@"View controller %@ is not in stack", viewController]; + NSLog(@"View controller %@ is not in stack", viewController); return @[]; } From 94bd5b352f0cd1891b5c45852ae7aa28b2a77fbd Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:28:31 -0800 Subject: [PATCH 07/10] Improved setViewControllers:animated: --- lib/UIKit/TUINavigationController.m | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 20d3d9e0..6defeeee 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -55,8 +55,33 @@ - (TUIViewController *)topViewController { #pragma mark - Methods - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { - [_stack removeAllObjects]; + CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; + + TUIViewController *viewController = [viewControllers lastObject]; + BOOL containedAlready = ([_stack containsObject:viewController]); + + [CATransaction begin]; + //Push if it's not in the stack, pop back if it is + [self.view addSubview:viewController.view]; + viewController.view.frame = containedAlready ? [self _offscreenLeftFrame] : [self _offscreenRightFrame]; + [CATransaction flush]; + [CATransaction commit]; + + TUIViewController *last = [self topViewController]; + + [_stack removeAllObjects]; [_stack addObjectsFromArray:viewControllers]; + + [TUIView animateWithDuration:duration animations:^{ + last.view.frame = containedAlready ? [self _offscreenRightFrame] : [self _offscreenLeftFrame]; + viewController.view.frame = self.view.bounds; + } completion:^(BOOL finished) { + [last.view removeFromSuperview]; + [viewController viewDidAppear:animated]; + [last viewDidDisappear:animated]; + }]; + + } - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)animated { From 6bbde5fd41859492e6bf6fbc55b75d6c36eee2a6 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:36:03 -0800 Subject: [PATCH 08/10] Switching to static c functions for offscreen frames --- lib/UIKit/TUINavigationController.m | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 6defeeee..aa6be161 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -63,7 +63,7 @@ - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { [CATransaction begin]; //Push if it's not in the stack, pop back if it is [self.view addSubview:viewController.view]; - viewController.view.frame = containedAlready ? [self _offscreenLeftFrame] : [self _offscreenRightFrame]; + viewController.view.frame = containedAlready ? TUINavigationOffscreenLeftFrame(self.view.bounds) : TUINavigationOffscreenRightFrame(self.view.bounds); [CATransaction flush]; [CATransaction commit]; @@ -73,7 +73,7 @@ - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { [_stack addObjectsFromArray:viewControllers]; [TUIView animateWithDuration:duration animations:^{ - last.view.frame = containedAlready ? [self _offscreenRightFrame] : [self _offscreenLeftFrame]; + last.view.frame = containedAlready ? TUINavigationOffscreenRightFrame(self.view.bounds) : TUINavigationOffscreenLeftFrame(self.view.bounds); viewController.view.frame = self.view.bounds; } completion:^(BOOL finished) { [last.view removeFromSuperview]; @@ -97,12 +97,12 @@ - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)an //Make sure the app draws the frame offscreen instead of just 'popping' it in [CATransaction begin]; - viewController.view.frame = [self _offscreenRightFrame]; + viewController.view.frame = TUINavigationOffscreenRightFrame(self.view.bounds); [CATransaction flush]; [CATransaction commit]; [TUIView animateWithDuration:duration animations:^{ - last.view.frame = [self _offscreenLeftFrame]; + last.view.frame = TUINavigationOffscreenLeftFrame(self.view.bounds); viewController.view.frame = self.view.bounds; } completion:^(BOOL finished) { [last.view removeFromSuperview]; @@ -144,7 +144,7 @@ - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(B [self.view addSubview:viewController.view]; - viewController.view.frame = [self _offscreenLeftFrame]; + viewController.view.frame = TUINavigationOffscreenLeftFrame(self.view.bounds); CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; @@ -152,7 +152,7 @@ - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(B [viewController viewWillAppear:animated]; [TUIView animateWithDuration:duration animations:^{ - last.view.frame = [self _offscreenRightFrame]; + last.view.frame = TUINavigationOffscreenRightFrame(self.view.bounds); viewController.view.frame = self.view.bounds; } completion:^(BOOL finished) { [last.view removeFromSuperview]; @@ -166,15 +166,13 @@ - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(B #pragma mark - Private -- (CGRect)_offscreenLeftFrame { - CGRect bounds = self.view.bounds; +static CGRect TUINavigationOffscreenLeftFrame(CGRect bounds) { CGRect offscreenLeft = bounds; offscreenLeft.origin.x -= bounds.size.width; return offscreenLeft; } -- (CGRect)_offscreenRightFrame { - CGRect bounds = self.view.bounds; +static CGRect TUINavigationOffscreenRightFrame(CGRect bounds) { CGRect offscreenRight = bounds; offscreenRight.origin.x += bounds.size.width; return offscreenRight; From 4f643f332fedaaff7644eb00acd8bc37112fd728 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:36:46 -0800 Subject: [PATCH 09/10] Inlined --- lib/UIKit/TUINavigationController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index aa6be161..5bbc46e0 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -166,13 +166,13 @@ - (NSArray *)popToViewController:(TUIViewController *)viewController animated:(B #pragma mark - Private -static CGRect TUINavigationOffscreenLeftFrame(CGRect bounds) { +static inline CGRect TUINavigationOffscreenLeftFrame(CGRect bounds) { CGRect offscreenLeft = bounds; offscreenLeft.origin.x -= bounds.size.width; return offscreenLeft; } -static CGRect TUINavigationOffscreenRightFrame(CGRect bounds) { +static inline CGRect TUINavigationOffscreenRightFrame(CGRect bounds) { CGRect offscreenRight = bounds; offscreenRight.origin.x += bounds.size.width; return offscreenRight; From f12e14d80fead7cc8d97c381fd06a2bbfab03d65 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Tue, 13 Nov 2012 19:41:00 -0800 Subject: [PATCH 10/10] Spaces -> tabs --- lib/UIKit/TUINavigationController.m | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/UIKit/TUINavigationController.m b/lib/UIKit/TUINavigationController.m index 5bbc46e0..65420f26 100644 --- a/lib/UIKit/TUINavigationController.m +++ b/lib/UIKit/TUINavigationController.m @@ -1,4 +1,4 @@ - // +// // TUINavigationController.m // TwUI // @@ -55,23 +55,23 @@ - (TUIViewController *)topViewController { #pragma mark - Methods - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { - CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; - - TUIViewController *viewController = [viewControllers lastObject]; - BOOL containedAlready = ([_stack containsObject:viewController]); - - [CATransaction begin]; - //Push if it's not in the stack, pop back if it is - [self.view addSubview:viewController.view]; + CGFloat duration = animated ? TUINavigationControllerAnimationDuration : 0; + + TUIViewController *viewController = [viewControllers lastObject]; + BOOL containedAlready = ([_stack containsObject:viewController]); + + [CATransaction begin]; + //Push if it's not in the stack, pop back if it is + [self.view addSubview:viewController.view]; viewController.view.frame = containedAlready ? TUINavigationOffscreenLeftFrame(self.view.bounds) : TUINavigationOffscreenRightFrame(self.view.bounds); [CATransaction flush]; [CATransaction commit]; - - TUIViewController *last = [self topViewController]; - - [_stack removeAllObjects]; + + TUIViewController *last = [self topViewController]; + + [_stack removeAllObjects]; [_stack addObjectsFromArray:viewControllers]; - + [TUIView animateWithDuration:duration animations:^{ last.view.frame = containedAlready ? TUINavigationOffscreenRightFrame(self.view.bounds) : TUINavigationOffscreenLeftFrame(self.view.bounds); viewController.view.frame = self.view.bounds; @@ -80,8 +80,6 @@ - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { [viewController viewDidAppear:animated]; [last viewDidDisappear:animated]; }]; - - } - (void)pushViewController:(TUIViewController *)viewController animated:(BOOL)animated { @@ -116,9 +114,9 @@ - (TUIViewController *)popViewControlerAnimated:(BOOL)animated { NSLog(@"Not enough view controllers on stack to pop"); return nil; } - TUIViewController *popped = [_stack lastObject]; + TUIViewController *popped = [_stack lastObject]; [self popToViewController:[_stack objectAtIndex:([_stack count] - 2)] animated:animated]; - return popped; + return popped; } - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {