测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2015年5月 |
由 Tim Shadel 维护。
TSAnimatedRootViewSwitcheroo
是一个简单的容器控制器,用于您的 UIWindow
的 rootViewController
,允许您从一个根控制器过渡到另一个。
TSAnimatedRootViewSwitcheroo
帮助您管理您的应用根控制器。在您的应用程序中通常有多个部分是非常常见的。例如
UITabBarController
与 UINavigationController
)UINavigationController
)UIViewController
)UIViewController
)TSAnimatedRootViewSwitcheroo
帮助您的应用在这几种非常不同的结构之间平稳过渡,使用 iOS 7 UIViewControllerAnimatedTransitioning 协议,包括像 VCTransitionsLibrary 这样的动画库。
首先,使用 Cocoapods 获取它
pod 'TSAnimatedRootViewSwitcheroo', '~> 1.0.0'
现在假设我们有一个单例类,该类创建我们单独的根控制器,界面简单如下
@interface AppRoots : NSObject
// Normal use
+ (UITabBarController *)appRoot;
// Other uses
+ (UIPageViewController *)introRoot;
+ (UINavigationController *)loggedOutRoot;
+ (UIViewController *)upgradingDBRoot;
+ (UIViewController *)networkDownRoot;
@end
然后我们就可以轻松地将 TSAnimatedRootViewSwitcheroo
添加进来,以帮助从一个根控制器切换到另一个。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *root = nil;
if (/* logged in */) {
root = [AppRoots appRoot];
} else {
root = [AppRoots introRoot];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [TSAnimatedRootViewSwitcheroo switcherooWithRoot:root andDelegate:self];
[self.window makeKeyAndVisible];
return YES;
}
- (void)signOut {
// Do some stuff
[TSAnimatedRootViewSwitcheroo useRoot:[AppRoots loggedOutRoot] direction:TSSwitcherooAnimationDirectionReverse];
}
- (void)signIn {
// Do some stuff
[TSAnimatedRootViewSwitcheroo useRoot:[AppRoots appRoot] direction:TSSwitcherooAnimationDirectionForward];
}
- (id<UIViewControllerAnimatedTransitioning>)switcheroo:(TSAnimatedRootViewSwitcheroo *)switcheroo
animationControllerForDirection:(TSSwitcherooAnimationDirection)direction
fromViewController:(UIViewController *)fromViewController
toViewController:(UIViewController *)toViewController {
// Let's use some awesome transitions from the VCTransitionsLibrary
CEReversibleAnimationController *animator = [CENatGeoAnimationController new];
animator.reverse = (direction == TSSwitcherooAnimationDirectionReverse);
return animator;
// If we want a Cube animation for login/logout, but a Flip animation for UpgradeDB => app
// then we'd check the fromViewController/toViewController pairs and return the right animation.
// Return nil for no animation.
}
@end
关键是,将 TSAnimatedRootViewSwitcheroo
用作您窗口的根 viewController
,然后您可以通过调用 + useRoot:direction:
来更改所需的根控制器。
您还可以完全控制用于在堆栈间过渡的动画,包括您创建的自定义动画。
因为这是一个实现了自定义容器控制器方法的 UIViewController
,所以您可以用它做很多事情。代码的演变将始终坚持将切换根控制器作为主要使用案例。