Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Removed support for custom animation #28

Merged
merged 2 commits into from

2 participants

@Drewsmits
Collaborator

The support for custom animation wasn't really there, and if you passed the "None" animation option, it still animated. I did all this on master, and figured a pull request was fitting, since you probably don't want your stuff to change underneath you!

Like we discussed, Pilot is now more like your app wide nav controller. You can push/pop view controllers outside of the show model workflow, which I have had to use. I was using custom animations, but now I'm not, so I just pulled that out.

-Andrew

Drewsmits added some commits
@Drewsmits Drewsmits Removed support for custom animations until we have a solid workflow.…
… Switched language around a bit to match Apple defaults. Added view controller pop.
d414183
@Drewsmits Drewsmits Clean up ca96373
@danieltiger danieltiger merged commit 08d2a75 into danieltiger:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2011
  1. @Drewsmits

    Removed support for custom animations until we have a solid workflow.…

    Drewsmits authored
    … Switched language around a bit to match Apple defaults. Added view controller pop.
Commits on Dec 15, 2011
  1. @Drewsmits

    Clean up

    Drewsmits authored
This page is out of date. Refresh to see the latest.
View
72 Pilot/Pilot.h
@@ -10,75 +10,75 @@
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
-
-
@interface Pilot : NSObject
/**
- *
+ Setup Pilot to use the input navigation controller for all navigation. Usually
+ You would build the navigation controller in your AppDelegat. See the PilotTestApp
+ for more details.
+
+ @params navigationController This will be used as the app-wide navigation controller
*/
+ (void)setupWithNavigationController:(UINavigationController *)navigationController;
-/**
- *
- */
+ (void)setupWithTabBarController:(UITabBarController *)tabBarController;
-/**
- * Reset Pilot to a clean state.
- */
-+ (void)reset;
++ (void)pushViewController:(id)viewController animated:(BOOL)animated;
-/**
- Pushes the objects view controller onto the stack
- */
-+ (void)showObject:(NSManagedObject *)object;
++ (void)presentViewControllerAsModal:(id)viewController animated:(BOOL)animated;
/**
- *
+ Pops the top view controller off the stack
*/
-+ (void)showObjectAsModal:(NSManagedObject *)object;
++ (void)popTopViewControllerAnimated:(BOOL)animated;
/**
- *
+ Returns the view controller class for the given NSManagedObject. This follows
+ a naming convention of "<Object Class Name>ViewController".
*/
-+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector;
++ (Class)viewControllerClassForObject:(NSManagedObject *)object;
/**
- *
+ The default initializer on the View Controller to be presented
*/
-+ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector;
++ (SEL)defaultInitializer;
/**
- *
+ Returns the current navigation controller. If using a Tabbar app, this will
+ return the current selected view controller
*/
-+ (void)showObject:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation;
++ (UINavigationController *)currentNavigationController;
/**
- Pushes the objects view controller onto the stack with the given animation transition
- over the given duration.
+ * Reset Pilot to a clean state.
*/
-+ (void)showObject:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration;
++ (void)reset;
/**
- *
+ Pushes the objects view controller onto the stack
*/
-+ (void)showObjectAsModal:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation;
++ (void)showObject:(NSManagedObject *)object;
-/**
- *
- */
-+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration;
++ (void)showObject:(NSManagedObject *)object animated:(BOOL)animated;
+
++ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector;
+
++ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated;
/**
- *
+ Pushes the objects view controller onto the stack as a modal ViewController
*/
-+ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation;
++ (void)showObjectAsModal:(NSManagedObject *)object;
+
++ (void)showObjectAsModal:(NSManagedObject *)object animated:(BOOL)animated;
+
++ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector;
+
++ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated;
/**
- Pushes the objects view controller onto the stack with the given animation transition
- over the given duration, and performs the designated selector.
+ All "show" actions filter down to this method
*/
-+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration asModal:(BOOL)asModal;
++ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated asModal:(BOOL)asModal;
@end
View
134 Pilot/Pilot.m
@@ -8,22 +8,61 @@
#import "Pilot.h"
-#define PILOT_ANIMATION_DURATION 0.3
-
-@interface Pilot (Private)
-+ (Class)viewControllerClassForObject:(NSManagedObject *)object;
-+ (SEL)defaultInitializer;
-+ (void)presentViewController:(id)viewController withAnimation:(UIViewAnimationTransition)animation;
-+ (void)presentViewControllerAsModal:(id)viewController withAnimation:(UIViewAnimationTransition)animation;
-+ (UINavigationController *)currentNavigationController;
-@end
-
static UINavigationController *rootNavigationController = nil;
static UITabBarController *rootTabBarController = nil;
@implementation Pilot
-#pragma mark - Private Methods
+#pragma mark - Setup
+
++ (void)setupWithNavigationController:(UINavigationController *)navigationController {
+ rootNavigationController = navigationController;
+}
+
++ (void)setupWithTabBarController:(UITabBarController *)tabBarController {
+ rootTabBarController = tabBarController;
+}
+
++ (void)reset {
+ rootNavigationController = nil;
+ rootTabBarController = nil;
+}
+
+#pragma mark - Navigation
+
++ (void)pushViewController:(id)viewController animated:(BOOL)animation {
+ [[self currentNavigationController] pushViewController:viewController
+ animated:animation];
+}
+
++ (void)presentViewControllerAsModal:(id)viewController animated:(BOOL)animated {
+ [[self currentNavigationController] presentModalViewController:viewController animated:animated];
+}
+
++ (void)popTopViewControllerAnimated:(BOOL)animated {
+ [[self currentNavigationController] popViewControllerAnimated:animated];
+}
+
+// TODO: Custom animations
+//+ (void)pushViewController:(id)viewController
+// withCustomAnimation:(UIViewAnimationTransition)animation
+// andDuration:(CGFloat)duration {
+//
+// if (animation != UIViewAnimationOptionTransitionNone) {
+// [UIView transitionWithView:[self currentNavigationController].view
+// duration:duration
+// options:animation
+// animations:^{
+// [[self currentNavigationController] pushViewController:viewController
+// animated:NO];
+// }
+// completion:NULL];
+// } else {
+// [self pushViewController:viewController animated:NO];
+// }
+//}
+
+#pragma mark -
+ (Class)viewControllerClassForObject:(NSManagedObject *)object {
@@ -43,26 +82,6 @@ + (SEL)defaultInitializer {
return NSSelectorFromString(@"initWithObjectURI:");
}
-+ (void)presentViewController:(id)viewController withAnimation:(UIViewAnimationTransition)animation andDuration:(CGFloat)duration {
-
- if (animation != UIViewAnimationOptionTransitionNone) {
- [UIView transitionWithView:[self currentNavigationController].view
- duration:duration
- options:animation
- animations:^{
- [[self currentNavigationController] pushViewController:viewController
- animated:NO];
- }
- completion:NULL];
- } else {
- [[self currentNavigationController] pushViewController:viewController animated:YES];
- }
-}
-
-+ (void)presentViewControllerAsModal:(id)viewController withAnimation:(UIViewAnimationTransition)animation {
- [[self currentNavigationController] presentModalViewController:viewController animated:YES];
-}
-
+ (UINavigationController *)currentNavigationController {
if (rootNavigationController) {
return rootNavigationController;
@@ -77,58 +96,41 @@ + (UINavigationController *)currentNavigationController {
return nil;
}
-#pragma mark - Public API
-
-+ (void)setupWithNavigationController:(UINavigationController *)navigationController {
- rootNavigationController = navigationController;
-}
-
-+ (void)setupWithTabBarController:(UITabBarController *)tabBarController {
- rootTabBarController = tabBarController;
-}
-
-+ (void)reset {
- rootNavigationController = nil;
- rootTabBarController = nil;
-}
+#pragma mark - Show
+ (void)showObject:(NSManagedObject *)object {
- [self showObject:object withSelector:[self defaultInitializer] animation:UIViewAnimationTransitionNone duration:PILOT_ANIMATION_DURATION asModal:NO];
-}
-
-+ (void)showObjectAsModal:(NSManagedObject *)object {
- [self showObject:object withSelector:[self defaultInitializer] animation:UIViewAnimationTransitionNone duration:PILOT_ANIMATION_DURATION asModal:YES];
+ [self showObject:object withSelector:[self defaultInitializer] animated:YES asModal:NO];
}
+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector {
- [self showObject:object withSelector:selector animation:UIViewAnimationTransitionNone duration:PILOT_ANIMATION_DURATION asModal:NO];
+ [self showObject:object withSelector:selector animated:YES asModal:NO];
}
-+ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector {
- [self showObject:object withSelector:selector animation:UIViewAnimationTransitionNone duration:PILOT_ANIMATION_DURATION asModal:YES];
++ (void)showObject:(NSManagedObject *)object animated:(BOOL)animated {
+ [self showObject:object withSelector:[self defaultInitializer] animated:animated asModal:NO];
}
-+ (void)showObject:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation {
- [self showObject:object withSelector:[self defaultInitializer] animation:animation duration:PILOT_ANIMATION_DURATION asModal:NO];
++ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated {
+ [self showObject:object withSelector:selector animated:animated asModal:NO];
}
-+ (void)showObject:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration {
- [self showObject:object withSelector:[self defaultInitializer] animation:animation duration:duration asModal:NO];
++ (void)showObjectAsModal:(NSManagedObject *)object {
+ [self showObject:object withSelector:[self defaultInitializer] animated:YES asModal:YES];
}
-+ (void)showObjectAsModal:(NSManagedObject *)object animation:(UIViewAnimationTransition)animation {
- [self showObject:object withSelector:[self defaultInitializer] animation:animation duration:PILOT_ANIMATION_DURATION asModal:YES];
++ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector {
+ [self showObject:object withSelector:selector animated:YES asModal:YES];
}
-+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration {
- [self showObject:object withSelector:selector animation:animation duration:duration asModal:NO];
++ (void)showObjectAsModal:(NSManagedObject *)object animated:(BOOL)animated {
+ [self showObject:object withSelector:[self defaultInitializer] animated:animated asModal:YES];
}
-+ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation {
- [self showObject:object withSelector:selector animation:animation duration:PILOT_ANIMATION_DURATION asModal:YES];
++ (void)showObjectAsModal:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated {
+ [self showObject:object withSelector:selector animated:animated asModal:YES];
}
-+ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animation:(UIViewAnimationTransition)animation duration:(CGFloat)duration asModal:(BOOL)asModal {
++ (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animated:(BOOL)animated asModal:(BOOL)asModal {
Class viewControllerClass = [self viewControllerClassForObject:object];
NSAssert([viewControllerClass instancesRespondToSelector:selector], @"PILOT ERROR: Could not find selector %@ for %@ViewController",
@@ -140,9 +142,9 @@ + (void)showObject:(NSManagedObject *)object withSelector:(SEL)selector animatio
id viewController = [[[viewControllerClass alloc] performSelector:selector withObject:object.objectID.URIRepresentation] autorelease];
if (asModal) {
- [self presentViewControllerAsModal:viewController withAnimation:animation];
+ [self presentViewControllerAsModal:viewController animated:animated];
} else {
- [self presentViewController:viewController withAnimation:animation andDuration:duration];
+ [self pushViewController:viewController animated:animated];
}
}
View
32 PilotTestApp/Classes/PTTestViewController.m
@@ -71,7 +71,7 @@ - (void)viewDidLoad {
// Red
UIButton *redButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [redButton setTitle:@"Show Red" forState:UIControlStateNormal];
+ [redButton setTitle:@"Show Red w/o Animation" forState:UIControlStateNormal];
[redButton addTarget:self action:@selector(redButtonAction) forControlEvents:UIControlEventTouchUpInside];
[redButton sizeToFit];
[self.view addSubview:redButton];
@@ -90,10 +90,22 @@ - (void)viewDidLoad {
[blueButton sizeToFit];
[self.view addSubview:blueButton];
+ // Pop
+ UIButton *popButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ [popButton setTitle:@"Pop" forState:UIControlStateNormal];
+ [popButton addTarget:self action:@selector(popButtonAction) forControlEvents:UIControlEventTouchUpInside];
+ [popButton sizeToFit];
+ [self.view addSubview:popButton];
+
+ // Pop Animated
+ UIButton *popAnimatedButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ [popAnimatedButton setTitle:@"Pop Animated" forState:UIControlStateNormal];
+ [popAnimatedButton addTarget:self action:@selector(popAnimatedButtonAction) forControlEvents:UIControlEventTouchUpInside];
+ [popAnimatedButton sizeToFit];
+ [self.view addSubview:popAnimatedButton];
+
// This is just a convience function to layout the title and buttons
[self layoutViews];
-
-
}
- (void)viewDidUnload {
@@ -106,7 +118,7 @@ - (void)viewDidUnload {
- (void)redButtonAction {
RedObject *newRedObject = [RedObject objectWithUniqueMessage];
- [Pilot showObject:newRedObject animation:UIViewAnimationOptionTransitionCurlDown duration:0.8];
+ [Pilot showObject:newRedObject animated:NO];
}
- (void)greenButtonAction {
@@ -119,6 +131,14 @@ - (void)blueButtonAction {
[Pilot showObject:newBlueObject];
}
+- (void)popButtonAction {
+ [Pilot popTopViewControllerAnimated:NO];
+}
+
+- (void)popAnimatedButtonAction {
+ [Pilot popTopViewControllerAnimated:YES];
+}
+
#pragma - Layout
- (void)layoutViews {
@@ -127,7 +147,7 @@ - (void)layoutViews {
if (i == 0) {
v.frame = CGRectMake(round(self.view.frame.size.width / 2 - v.frame.size.width / 2),
- round(v.frame.size.height + 20),
+ round(v.frame.size.height + 10),
v.frame.size.width,
v.frame.size.height);
} else {
@@ -135,7 +155,7 @@ - (void)layoutViews {
UIView *v0 = [self.view.subviews objectAtIndex:(i - 1)];
v.frame = CGRectMake(round(self.view.frame.size.width / 2 - v.frame.size.width / 2),
- round(v0.frame.origin.y + v0.frame.size.height + 20),
+ round(v0.frame.origin.y + v0.frame.size.height + 10),
v.frame.size.width,
v.frame.size.height);
}
Something went wrong with that request. Please try again.