Giter VIP home page Giter VIP logo

adtransitioncontroller's Introduction

ADTransitionController - 3D transitions for your apps

ADTransitionController brings all the power of the Core Animation framework to your apps with nice pre-defined transitions.

  • For apps supporting iOS 7 and beyond, we have a very generic API that uses the new UIViewControllerTransitioningDelegate protocol, making it usable for any transition (navigation, modal, tab bar).
  • If you also need to support iOS 6, we give you a drop-in replacement for UINavigationController that adds support for our transitions.

Installation

Basic

  1. Add the content of the ADTransitionController folder to your iOS project
  2. Link against the QuartzCore Framework if you don't already
  3. Import ADTransitionController.h in your project

CocoaPods

  1. Add pod 'ADTransitionController' to your Podfile
  2. In your terminal run $ pod install and open your workspace $ open yourApp.xcworkspace
  3. Import <ADTransitionController.h> in your project

ARC

If you are not using ARC in your project, use the -fobjc-arc flag in Build Phases > Compile Sources.

Example

Your project is now ready to take advantage of ADTransitionController. Here are two examples of how to use it. One if you plan to develop for iOS 7 and later, the other one if you want to support iOS 6 too.

iOS 7 and later

We're making use of the new UIViewControllerTransitioningDelegate protocol. The API provided by Apple is quite complex, but we made it very simple to use.

In short:

  1. Set the delegate of your navigation controller to the one that we give you.
  2. Make your view controller inherit from ADTransitioningViewController (if this is not an option for you, see below).
  3. Set the transition property of your view controller to your favorite transition.

In details:

First of all, create your UINavigationController and set its delegate to a ADNavigationControllerDelegate instance.

#import "ADNavigationControllerDelegate.h"
...
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
ADNavigationControllerDelegate * navigationDelegate = [[ADNavigationControllerDelegate alloc] init];
navigationController.delegate = navigationDelegate;
self.window.rootViewController = navigationController;
[navigationController release];

Then create your new controller (that inherits from ADTransitioningViewController), set its transition and push it onto the stack. In this example, this will animate the transition with a cube effect.

UIViewController * newViewController = [[UIViewController alloc] init];
ADTransition * transition = [[ADCubeTransition alloc] initWithDuration:0.25f orientation:ADTransitionRightToLeft sourceRect:self.view.frame];
newViewController.transition = transition;
[self.navigationController pushViewController:newViewController animated:YES];
[transition release];
[newViewController release];

If your view controller can't inherit from ADTransitioningViewController, you can use directly an ADTransitioningDelegate object to control the transition.

UIViewController * newViewController = [[UIViewController alloc] init];
ADTransition * transition = [[ADCubeTransition alloc] initWithDuration:0.25f orientation:ADTransitionRightToLeft sourceRect:self.view.frame];
ADTransitioningDelegate * transitioningDelegate = [[ADTransitioningDelegate alloc] initWithTransition:transition];
newViewController.transitioningDelegate = transitioningDelegate;
[self.navigationController pushViewController:newViewController animated:YES];
[transition release];
[newViewController release];

Under the hood

To create a custom animation, Apple provides different protocols we have implemented for you : UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning, UIViewControllerContextTransitioning. That way, you shouldn't bother to dig into these APIs.

As we have just seen it, in practice, what you only have to do on iOS7 is to create a UINavigationController, and a ADTransition.

To sum up, we provide three different classes you may want to use :

  • ADNavigationControllerDelegate : used when you setup your navigation controller to perform custom animations
  • ADTransitioningViewController : used for your view controllers to control their transitions
  • ADTransitioningDelegate : used only if you can't inherit from ADTransitioningViewController and need to specify the transitioning delegate for the view controller

iOS 6 and later

If you need to support earlier versions of iOS, this is possible. Just use ADTransitionController instead of UINavigationController.

Instantiate an ADTransitionController like a UINavigationController:

UIViewController * viewController = [[UIViewController alloc] init];
ADTransitionController * transitionController = [[ADTransitionController alloc] initWithRootViewController:viewController];
[viewController release];
self.window.rootViewController = transitionController;
[transitionController release];

To push a viewController on the stack, instantiate an ADTransition and use the pushViewController:withTransition: method.

- (IBAction)pushWithCube:(id)sender {
    UIViewController * viewController = [[UIViewController alloc] init];
    ADTransition * transition = [[ADCubeTransition alloc] initWithDuration:0.25f orientation:ADTransitionRightToLeft sourceRect:self.view.frame];
    [self.transitionController pushViewController:viewController withTransition:transition];
    [transition release];
    [viewController release];
}

To pop a viewController from the stack, just use the popViewController method.

- (IBAction)pop:(id)sender {
    [self.transitionController popViewController];
}

Note

When a UIViewController is pushed onto the stack of view controllers, the property transitionController becomes available to the controller (see example above: self.transitionController). This way, an ADTransitionController can be used like a UINavigationController.

ADTransition subclasses

For now, the built-in transitions available are the following. Try out our demo application to see them in action!

ADCarrouselTransition, ADCubeTransition, ADCrossTransition, ADFlipTransition, ADSwapTransition, ADFadeTransition, ADBackFadeTransition, ADGhostTransition, ADZoomTransition, ADSwipeTransition, ADSwipeFadeTransition, ADScaleTransition, ADGlueTransition, ADPushRotateTransition, ADFoldTransition, ADSlideTransition.

ADTransitionController API

The ADTransitionController API is fully inspired by the UINavigationController, to be very easy to integrate in your projects. The few differences between the two APIs are presented below.

Methods

The point of ADTransitionController is to be able to customize the animations for a transition between two UIViewController instances. Here are the methods we added to let you take advantage of the built-in transitions:

- (void)pushViewController:(UIViewController *)viewController withTransition:(ADTransition *)transition;
- (UIViewController *)popViewControllerWithTransition:(ADTransition *)transition;
- (NSArray *)popToViewController:(UIViewController *)viewController withTransition:(ADTransition *)transition;
- (NSArray *)popToRootViewControllerWithTransition:(ADTransition *)transition;

Here are the convention for the push and pop actions:

  • pass nil to the transition parameter to disable the animation. Thus the transition won't be animated.
  • pass an ADTransition instance to the transition parameter to animate the push action.
  • by default the pop action uses the reverse animation used for the push action. However you can pass a different transition to the transition parameter to change this behavior.

Delegate

Like a UINavigationController, an ADTransitionController informs its delegate that a viewController is going to be presented or was presented. The delegate implements the ADTransitionControllerDelegate protocol.

@property (nonatomic, assign) id<ADTransitionControllerDelegate> delegate;
@protocol ADTransitionControllerDelegate <NSObject>
- (void)transitionController:(ADTransitionController *)transitionController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)transitionController:(ADTransitionController *)transitionController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
@end

Going Further

If you want to totally take control of the ADTransitionController API, feel free to create your own transitions and animations! All you need to do is to subclass ADDualTransition or ADTransformTransition and implement a init method.

The simplest example of a custom transition is the ADFadeTransition class. The effect is simple: the inViewController fades in. For this the inViewController changes its opacity from 0 to 1 and the outViewController from 1 to 0.

@interface ADFadeTransition : ADDualTransition
@end
@implementation ADFadeTransition
- (id)initWithDuration:(CFTimeInterval)duration {
    CABasicAnimation * inFadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    inFadeAnimation.fromValue = @0.0f;
    inFadeAnimation.toValue = @1.0f;
    inFadeAnimation.duration = duration;
    
    CABasicAnimation * outFadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    outFadeAnimation.fromValue = @1.0f;
    outFadeAnimation.toValue = @0.0f;
    outFadeAnimation.duration = duration;
    
    self = [super initWithInAnimation:inFadeAnimation andOutAnimation:outFadeAnimation];
    return self;
}
@end

This example is really basic and if you want to create more funky effects, just have a look to the following API and the examples we provided.

ADTransition API

The ADTransition class is an abstract class that has two abstract subclasses: ADDualTransition and ADTransformTransition.

Instances of ADDualTransition have two importants properties:

@property (nonatomic, readonly) CAAnimation * inAnimation;
@property (nonatomic, readonly) CAAnimation * outAnimation;

The inAnimation is the CAAnimation that will be applied to the layer of the viewController that is going to be presented during the transition. The outAnimation is the CAAnimation that will be applied to the layer of the viewController that is going to be dismissed during the transition.

Instance of ADTransformTransition have three importants properties:

@property (readonly) CAAnimation * animation;
@property (readonly) CATransform3D inLayerTransform;
@property (readonly) CATransform3D outLayerTransform;

The inLayerTransform is the CATransform3D that will be applied to the layer of the viewController that is going to be presented during the transition. The outLayerTransform is the CATransform3D that will be applied to the layer of the viewController that is going to be dismissed during the transition. The animation is the CAAnimation that will be applied to the content layer of the ADTransitionController (i.e. the parent layer of the two former viewController layers).

Future Work

There are a couple of improvements that could be done. Feel free to send us pull requests if you want to contribute!

  • Add new custom transitions
  • Add support for non plane transitions (Fold transition for instance)
  • More?

adtransitioncontroller's People

Contributors

farfromrefug avatar felginep avatar fwaddle avatar laviallb avatar yosit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adtransitioncontroller's Issues

having issues with view controller

hi,

your project is very cool - thanks!

but, am trying to use it per the demo - similar to a drop in replacement for UINavCon
i have a loadview in my main ViewCon which creates and loads the view.
everything was working for long time, but now with your transition controller, my main view gets shrunk to a small rect at the top left - i've checked the frame bounds, etc. they are fine - any idea?

am not able to use your awesome product - plz help - thx
paul.

View has been resized after transition

I have the following configuration - UIViewController placed in UINavigationController which is placed in UITabBarController.

My view is added as subview to the view of UIViewController and has constraints to fill the space between navigation bar and tab bar. Everything works if I do not use transitions (ADTransitionController does not work). When I activate ADTransitionController the animation itself works fine but when it's completed I find that my view has been resized - the new height is smaller by 49 points (the height of Tab bar).

It looks like ADTransitionController is responsible for the resizing of my view but I cannot understand the reason and find where it happens. Could you help me?
Thanks in advance!

navigationBar in Landscape

Just realized that the navigationBar doesnt change it s height on orientation change.
Not sure why yet

Flicker at the end of transition animation.

If the two transitioning views have transparent backgrounds, you see a flicker at the end of the animation.

I resolved it by adding the following in ADDualTransition.m, at the end of finishInit

_inAnimation.fillMode = _outAnimation.fillMode = kCAFillModeForwards;
_inAnimation.removedOnCompletion = _outAnimation.removedOnCompletion = NO;

I haven't tested across all transitions, but it seems to do the trick for ADSwipeTransition.

ios7 support

ADTransitionController doesn't seem to be supporting new ios7 features like:

  • edgesForExtendedLayout
  • extendedLayoutIncludesOpaqueBars
  • automaticallyAdjustsScrollViewInsets
  • translucent

View becomes detached from window

In certain circumstances the main view becomes detached from the window after a transition. If I try to update the parent viewcontroller due to orientation changes for example. When I come back it appears and then immediately disappears after viewDidAppear. Occasionally, the same is true for viewcontroller I move towards. The viewcontroller appears then immediately disappears after transition. Any thoughts?

Could you rename the "CGRectCenter" function in DTUtils.m?

When I integrate the ADTransitionController and DTCoreText with CocoaPods,I get the compiling error:

duplicate symbol _CGRectCenter in:
/Users/jcccn/Library/Developer/Xcode/DerivedData/XXX-dfwqdrktuxtadrbmltnhcihaucsu/Build/Products/Debug-iphonesimulator/libPods.a(ADZoomTransition.o)
/Users/jcccn/Library/Developer/Xcode/DerivedData/XXX-dfwqdrktuxtadrbmltnhcihaucsu/Build/Products/Debug-iphonesimulator/libPods.a(DTUtils.o)
ld: 1 duplicate symbol for architecture i386

And I haven't got a resolution for that.

So, If you can help me fix that, then thank you so so much.

iOS7

are you migrating your fantastic code to iOS7?
i need it, soon ;)

thanks for your work!

won't work with orientation change

I just wanted to let you know that most transitions wont work with orientation change.
The reason is quite simple.
you set the animations rect during int. This is wrong. You should init the animation just before using it.
A simple example of failure

  1. rotate your device to landscape
  2. open a controller with SWIPE
  3. rotate your device to portrait
  4. popViewController

See the animation not working (which is totally normal!)

I will rewrite transitions for it to work. Let me know if you want a PR

CertUIFramework.axbundle (not loaded)

Hi all,
I integrated ADTransitionController into my app but when I run it into simulator, I get this error:

Cannot find executable for CFBundle 0x9b99ad0 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)

Can you help me please?

Thanks

Luca

Demo project problem & Crash

Hey,

I just ran the demo project and got a crash: When I do some transitions and then press back till I'm back at the beginning and then trigger another transition the demo app crashes. Does anyone else see this / know what do about it?

In the video I'm seen, the title text in the middle of the navigation bar does swipe to the right when a transitions happens (Just like with a normal UINavigationController). When running them demo project and my phone and iPad this does not happen. The title test just changes. What is wrong here?

Xcode 7 GM build failed

'objc_designated_initializer' attribute only applies to init methods of interface or class extension declarations

  • (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil NS_DESIGNATED_INITIALIZER;

Using ADTransitioningDelegate with UITabBarControllerDelegate

I would like to use ADTransitionController with UITabBarController.
Based on the example for UINavigationController I created a delegate for UITabBarController and used ADTransitioningDelegate there.

Everything was fine but after 3 switches between tabs the app was stuck and stopped working.

Is there any issues when working with UITabBarController?

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.