测试已测试 | ✗ |
语言语言 | MUMPSMUMPS |
许可协议 | MIT |
发布时间最后发布 | 2015年2月 |
由 Gareth Shapiro 维护。
这是一个基于 UINavigationController 的视图堆栈,它接收 NSNotifications 中的通知以导航到之前已注册的 UIViewControllers,从而实现解耦架构。
这个库设计得非常易于使用,掩盖了使用它所获得的大幅提升的灵活性。
如果您在本 GitHub 页面上阅读,请点击此处获取文档。
如果您想获得更深入的教程,请访问此处。
如果您急于了解更多信息,我可以创建一个示例项目,它展示了基本用法,并应能够在短时间内让您掌握。
除了可在 GitHub 上找到,这个库还可在 CocoaPods 上找到。
platform :ios, "6.1"
pod 'SimpleIOSViewStackController' , '3.1.10'
这个视图堆栈基于 UINavigationController,行为非常相似。只有在需要时才会将 UIViewControllers 放入堆栈,而且在用户面前得到它们是通过从应用程序的任何地方发布一个 NSNotification 来实现的。
对于每个 UIViewController,有两大关键步骤
在发生在此之前,您需要一个 SimpleIOSViewStackController 实例。就像您会在任何 UINavigationController 中做的那样来做这件事。例如,如果您正在设置应用程序的根ViewController在应用程序代理中,您的代码将类似于以下内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[RootNavigationController alloc] init];
self.window.rootViewController.view.frame = self.window.frame;
[self.window makeKeyAndVisible];
return YES;
}
其中 RootNavigationController 是 SimpleViewController 的子类
#import "SimpleIOSViewStackController.h"
@interface RootNavigationController : SimpleIOSViewStackController
@end
支持自定义导航栏和工具栏
self.window.rootViewController = [[RootNavigationController alloc] initWithNavigationBarClass: CustomNavigationBarClass toolbarClass:CustomToolBarClass
将要被这个视图堆栈管理的 UIViewControllers 的注册可以在它的 init 方法中进行,并提供了三种情况
SimpleIOSViewStackVO *__classViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString:@"ShowClassViewController"
viewControllerClass:[ClassViewController class]
storyboardID:nil
storyboardName:nil
nibName:nil];
SimpleIOSViewStackVO *__nibViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString:@"ShowNibViewController"
viewControllerClass:[NibViewController class]
storyboardID:nil
storyboardName:nil
nibName:nil];
SimpleIOSViewStackVO *__storyboardViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString: @"ShowStoryboardViewController"
viewControllerClass : [StoryboardViewController class]
storyboardID: @"StoryboardViewController"
storyboardName: nil // If you want to specify a specific storyboard. <- Do every time.
nibName: nil];
如果你的应用程序中只有一个场景树,那么你不需要在每个 UIViewController 上指定它,只需设置一次即可。
self.storyboardName = @"Main"; // If you only have one storyboard. <- Do once.
无论你的 UIViewController 如何创建和注册,当视图堆栈要显示它时,语法都是相同的。
[[NSNotificationCenter defaultCenter] postNotificationName: @"ShowClassViewController" object:nil];
这是最基本的通知形式,它会导致简单地显示一个 ClassViewController 实例,没有任何动画,并且删除当时正在显示的 UIViewController,如果有的话。
当然,你可能不希望这样,而有动画的过渡以及保留之前的 UIViewController 是通过使用 NSNotification 发送负载来轻松解决的。
[[NSNotificationCenter defaultCenter]
postNotificationName: @"ShowClassViewController"
object:
[[SimpleIOSViewStackNotificationVO alloc]
initWithAnimationFlag:YES
AndRemoveFlag:NO
]];
你可以变得稍微复杂一些,当需要在视图堆栈中添加新的 UIViewController 实例时,而不是回收先前的实例,还可以选择使用另一个 SimpleIOSViewStackNotificationVO 初始化器向 UIViewController 发送一些数据。
[[NSNotificationCenter defaultCenter]
postNotificationName:SHOW_CLASS_VIEW_CONTROLLER
object:
[[SimpleIOSViewStackNotificationVO alloc]
initWithAnimation:YES
removeCurrent:NO
recycleTarget:NO
dictionaryForView:@{ @"property" : @"value" }
]];
如果向上述的 dictionaryForView 提供一个 NSDictionary,它将在 UIVIewController 初始化或已在其中(动画之前)设置为的目标。
为了使所有这些正常工作,UIViewController 需要遵守 SimpleIOSViewStackDelegate 协议。
@interface ClassViewController : UIViewController<SimpleIOSViewStackDelegate>
@property (nonatomic, strong) NSDictionary *viewDictionary;
@end
这允许你创建一个用于视图字典的设置器,在其中你能够在 UIViewController 对用户可见之前检索字典的内容。
-(void)setViewDictionary:(NSDictionary *)value{
NSLog(@"%@" , value);
}
SimpleIOSViewStackController 有一个属性 numberOfChildrenToShowNavigationBar,它接受一个 NSNumber。如果设置了此属性,则确定一个阈值,根据该阈值显示或隐藏导航栏。使用方式类似于 navigationBarHidden,但不是在单个 UIViewControllers 上设置它,而是在达到阈值时会显示或隐藏导航栏。
例如,当视图堆栈上只有一个 UIViewController 时,可以没有导航栏,当添加一个时,可以出现一个。