Skip to content

Commit

Permalink
added README
Browse files Browse the repository at this point in the history
  • Loading branch information
azimin committed Nov 2, 2016
1 parent 577a3b3 commit ccfa2e8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# AZTransitions
Make your modal transition with custom animation.
AZTransitions helps you think about creativity, giving specific API methods.

## Visual Example

Inside this repository you can try `iOS Example` target with example `FashionTransition.swift` class:

![alt tag](imgs/animation_example.gif)

## Installation

- Add the following to your [`Podfile`](http://cocoapods.org/) and run `pod update`
```
pod 'AZTransitions'
```
- or add the following to your [`Cartfile`](https://github.com/Carthage/Carthage) and run `carthage update`
```
github "azimin/AZTransitions"
```
- or clone as a git submodule,

- or just copy ```AZTransitions/Source/CustomModalTransition.swift``` into your project.

## Code Example

To create any custom transition just subclass `CustomModalTransition`:

```swift
class FashionTransition: CustomModalTransition {
override init() {
super.init(duration: 0.5)
}
}
```
--

Then set as `az_modalTransition` to nessesary view just before presenting it
```swift
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
segue.destination.az_modalTransition = FashionTransition()
}
```
or
```swift
func show() {
let viewController = UIViewController()
viewController.az_modalTransition = FashionTransition()
self.present(viewController, animated: true, completion: nil)
}
```
--

To have custom present animation, just implement `performTransition(interactive: Bool)` inside your `FashionTransition` class:
```swift
func performTransition(interactive: Bool) {
self.presentedViewController.view.alpha = 0.0

UIView.animate(withDuration: duration, animations:
{
self.presentedViewController.view.alpha = 1.0
self.presentingViewController.view.alpha = 0.0
}, completion: {
(completed) in
self.presentingViewController.view.alpha = 1.0
self.finishAnimation(completion: nil)
})
}
```

As you guess you have different properties, mains is:
- `duration` transition duration
- `presentingViewController` view controller, that presenting your view controller
- `presentedViewController` view cotnroller that is going to be presented

You can animate them as you want.

**🔥IMPORTANT🔥** don't forget to call `finishAnimation(completion: nil)` in the end.

In this case animation will be:

![alt tag](imgs/animation_code_example.gif)

## More

You have different properties and methods to help you:
- `performDismissingTransition(interactive: Bool)` to implement custom dismissing transition animation
- `transitionContainerView` view where transition take place (`resentingViewController.view` and `presentedViewController.view` located on inside `transitionContainerView`), so you can add you custom views here to make animation more interesting (example inside `iOS Example`)
- Some methods for interactive animations (example would be added be soon)
- Some method to work with orientation changing things (example would be added be soon)
4 changes: 4 additions & 0 deletions iOS Example/FirstController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class FirstController: UIViewController {

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
segue.destination.az_modalTransition = FashionTransition()

let viewController = UIViewController()
viewController.az_modalTransition = FashionTransition()
self.present(viewController, animated: true, completion: nil)
}
}

Binary file added imgs/animation_code_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/animation_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ccfa2e8

Please sign in to comment.