在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):ColinEberhardt/VCTransitionsLibrary开源软件地址(OpenSource Url):https://github.com/ColinEberhardt/VCTransitionsLibrary开源编程语言(OpenSource Language):Objective-C 99.3%开源软件介绍(OpenSource Introduction):View Controller Transitions LibraryWith iOS 7 you can easily create custom view controller transitions that can be used in a range of contexts (push, pop, modal …). This project provides a library of custom animations which can be dropped directly into your project. It also has a number of 'interaction controllers' which can be used with any of the custom animations in order to make your transitions interactive. The library currently contains the following animations, which can be made interactive with either a swipe or pinch gesture.
Contents
A brief introduction to custom transitionsThe following provides a very brief introduction to the concepts, for more detailed coverage I would thoroughly recommend reading Chapter 3 of iOS 7 By Tutorials - which I wrote! (I've heard the other 15 chapters are pretty good too ;-) There are two key classes involved in a custom transition:
NOTE: Animation and interaction controllers are entirely independent, this means you can wire up any interaction controller with any animation controller - which is pretty awesome. Adding custom transitions to your projectThis sections gives a brief overview of the steps required to add custom view controller transitions to your project. You might also want to look at the code for the demo app (in the Grabbing the codeThere are a couple of ways you can incorporate transitions from this library into your code:
Using an animation controllerThe Custom present / dismiss transitionsThe Custom navigation controller transitionsThe Notice that this message has an 'operation' argument that allows you to return different animations for push and pop operations. All of the animation controllers in this library subclass - (id<UIViewControllerAnimatedTransitioning>)navigationController:
(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
// reverse the animation for 'pop' transitions
_animationController.reverse = operation == UINavigationControllerOperationPop;
return _animationController;
} Custom tab bar controller transitionsThe In order to determine the animation direction, you can compare the indices of the two view controller as shown below: - (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
animationControllerForTransitionFromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
NSUInteger fromVCIndex = [tabBarController.viewControllers indexOfObject:fromVC];
NSUInteger toVCIndex = [tabBarController.viewControllers indexOfObject:toVC];
_animationController.reverse = fromVCIndex < toVCIndex;
return _animationController;
} Using an interaction controllerInteraction controllers work in conjunction with an animation controller in order to make a transitions interactive, i.e. allow a user to control a transitions using gestures. This interactivity allows a use to move forwards, backwards and even cancel a transitions. The interaction controller is responsible for adding gesture recognisers to the view and triggering the navigation in response to gestures from the user. Interactive dismiss transitionsThe // instance variables, typically instantiated in your init method
CEFlipAnimationController *_animationController;
CESwipeInteractionController *_interactionController;
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
// allow the interaction controller to wire-up its gesture recognisers
[_interactionController wireToViewController:presented
forOperation:CEInteractionOperationDismiss];
_animationController.reverse = NO;
return _animationController;
}
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController *)dismissed {
_animationController.reverse = YES;
return _animationController;
}
- (id<UIViewControllerInteractiveTransitioning>)
interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator {
// provide the interaction controller, if an interactive transition is in progress
return _interactionController.interactionInProgress
? _interactionController : nil;
} Note that in the above code the Interactive pop transitionsThe // instance variables, typically instantiated in your init method
CEFlipAnimationController *_animationController;
CESwipeInteractionController *_interactionController;
- (id<UIViewControllerAnimatedTransitioning>)
navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
// wire the interaction controller to the to- view controller
[_interactionController wireToViewController:toVC
forOperation:CEInteractionOperationPop];
_animationController.reverse = operation == UINavigationControllerOperationPop;
return _animationController.reverse;
}
- (id <UIViewControllerInteractiveTransitioning>)
navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>)animationController {
// provide the interaction controller, if an interactive transition is in progress
return _interactionController.interactionInProgress
? _interactionController : nil;
} Interactive tab transitionsThe @implementation TabBarViewController {
CEFoldAnimationController *_animationController;
CESwipeInteractionController *_swipeInteractionController;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
self.delegate = self;
// create the interaction / animation controllers
_swipeInteractionController = [CESwipeInteractionController new];
_animationController = [CEFoldAnimationController new];
_animationController.folds = 3;
// observe changes in the currently presented view controller
[self addObserver:self
forKeyPath:@"selectedViewController"
options:NSKeyValueObservingOptionNew
context:nil];
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([keyPath isEqualToString:@"selectedViewController"] )
{
// wire the interaction controller to the view controller
[_swipeInteractionController wireToViewController:self.selectedViewController
forOperation:CEInteractionOperationTab];
}
}
- (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
animationControllerForTransitionFromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
NSUInteger fromVCIndex = [tabBarController.viewControllers indexOfObject:fromVC];
NSUInteger toVCIndex = [tabBarController.viewControllers indexOfObject:toVC];
_animationController.reverse = fromVCIndex < toVCIndex;
return _animationController;
}
-(id<UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
{
return _swipeInteractionController.interactionInProgress ? _swipeInteractionController : nil;
}
@end Transitions LibraryThe following is a graphical illustration of the various transitions. All animation controllers have a Fold animation - CEFoldAnimationControllerAnimates between the two view controllers using a paper-fold style transition. You can configure the number of folds via the Flip animation - CEFlipAnimationControllerAnimates between the two view controllers using a page-flip transition. NatGeo animation - CENatGeoAnimationControllerAnimates between the two view controllers using transition inspired by City Guides by National Geographic. It's an adoptation of MHNatGeoViewControllerTransition to iOS7 APIs. Turn animation - CETurnAnimationControllerAnimates between the two view controllers by performing a 3D flip, to reveal the destination view on the back.The turn animation has a Crossfade animation - CECrossfadeAnimationControllerAnimates between the two view controllers by performing a simple cross-fade. Explode animation - CEExplodeAnimationControllerAnimates between the two view controllers by slicing the from- view controller into lots of little pieces, then randomly spinning and shrinking them. Cards animation - CECardsAnimationControllerGives the impression of one view controller pushing the other to the back. It looks a lot more cool than these static screenshots! (courtesy of Tope - AppDesignVault) Portal animation - CEPortalAnimationControllerThe top-most view controller parts in the middle to reveal the view controller beneath. (courtesy of FreddyF) Cube animation - CECubeAnimationControllerThis transition gives the appearance of rotating the faces of a cube. (courtesy of Andrés Brun) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论