测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2014年12月 |
由 Dominik Hauser 维护。
使用 UIDynamic
行为进行自定义视图控制器过渡。
快速查看
重力
重力 + 旋转
创建一个 DDHNavigationControllerDelegate
实例,并将其设置为您的导航控制器的代理。
示例
#import "DDHAppDelegate.h"
#import "DDHFirstViewController.h"
#import "DDHNavigationControllerDelegate.h"
@interface DDHAppDelegate ()
@property (nonatomic, strong) DDHNavigationControllerDelegate *navigationControllerDelegate;
@end
@implementation DDHAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DDHFirstViewController *firstViewController = [[DDHFirstViewController alloc] initWithNibName:@"DDHFirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.navigationControllerDelegate = [[DDHNavigationControllerDelegate alloc] initWithTransitionType:1];
navigationController.delegate = self.navigationControllerDelegate;
self.window.rootViewController = navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
重要:导航控制器会指定其代理。因此,您需要在某个地方获取导航控制器代理的引用,您可以在 Interface Builder 中设置或像示例中那样在代码中设置。
要动态更改过渡类型,设置导航控制器代理的 transitionType。
#import "DDHNavigationControllerDelegate.h"
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
((DDHNavigationControllerDelegate*)self.navigationController.delegate).transitionType = DDH_TRANSITION_TYPE_GRAVITY;
}
#import "DDHNavigationControllerDelegate.h"
...
- (void)pushSecondViewController {
((DDHNavigationControllerDelegate*)self.navigationController.delegate).transitionType = DDH_TRANSITION_TYPE_GRAVITY;
DDHSecondViewController *secondViewController = [[DDHSecondViewController alloc] initWithNibName:@"DDHSecondViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
}
如果您不希望在您的代码中包含头文件,您可以使用键值编码。
[(NSObject*)self.navigationController.delegate setValue:@1 forKey:@"transitionType"];
ARC 和 iOS7。
下载项目,并将文件 DDHNavigationControllerDelegate.{h,m}
和目录 DynamicTransitionAnimators
添加到您的项目中。
Dominik Hauser,[email protected]
DDHDynamicViewControllerTransitions 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。