Skip to content

alexiscn/MTTransitions

Repository files navigation

MTTransitions

Transitions ports from GL-Transitions to Metal.

Features

  • Up to 76 transitions
  • Image Transitions
  • UIView Transitions
  • UIViewController Push Transtions
  • UIViewController Present Transitions
  • Video Merge Transitions
  • Create video from images with transitions
  • Create video from images with transitions and background music

Requirements

  • iOS 10.0 +
  • Xcode 11.0 +
  • Swift 5.0 +

Transitions

Support Following Transitions:

  • MTAngularTransition
  • MTBounceTransition
  • MTBowTieHorizontalTransition
  • MTBowTieVerticalTransition
  • MTBurnTransition
  • MTButterflyWaveScrawlerTransition
  • MTCannabisleafTransition
  • MTCircleCropTransition
  • MTCircleTransition
  • MTCircleOpenTransition
  • MTColorPhaseTransition
  • MTColourDistanceTransition
  • MTCrazyParametricFunTransition
  • MTCrossZoomTransition
  • MTCrossHatchTransition
  • MTCrossWarpTransition
  • MTCubeTransition
  • MTDirectionalTransition
  • MTDirectionalWarpTransition
  • MTDirectionalWipeTransition
  • MTDisplacementTransition
  • MTDoomScreenTransition
  • MTDoorwayTransition
  • MTDreamyTransition
  • MTDreamyZoomTransition
  • MTFadeTransition
  • MTFadeColorTransition
  • MTFadegrayscaleTransition
  • MTFlyeyeTransition
  • MTGlitchDisplaceTransition
  • MTGlitchMemoriesTransition
  • MTGridFlipTransition
  • MTHeartTransition
  • MTHexagonalizeTransition
  • MTInvertedPageCurlTransition
  • MTKaleidoScopeTransition
  • MTLinearBlurTransition
  • MTLumaTransition
  • MTLuminanceMeltTransition
  • MTMorphTransition
  • MTMosaicTransition
  • MTMultiplyBlendTransition
  • MTPerlinTransition
  • MTPinwheelTransition
  • MTPixelizeTransition
  • MTPolarFunctionTransition
  • MTPolkaDotsCurtainTransition
  • MTRadialTransition
  • MTRandomSquaresTransition
  • MTRippleTransition
  • MTRotateScaleFadeTransition
  • MTSimpleZoomTransition
  • MTSquaresWireTransition
  • MTSqueezeTransition
  • MTStereoViewerTransition
  • MTSwapTransition
  • MTSwirlTransition
  • MTTangentMotionBlurTransition
  • MTTVStaticTransition
  • MTUndulatingBurnOutTransition
  • MTWaterDropTransition
  • MTWindTransition
  • MTWindowBlindsTransition
  • MTWindowSliceTransition
  • MTWipeDownTransition
  • MTWipeLeftTransition
  • MTWipeRightTransition
  • MTWipeUpTransition
  • MTZoomInCirclesTransition

Installation

MTTransitions is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod MTTransitions

Get Started

Each transition requires two input MTIImage. Image should be .oriented(.downMirrored).

import MTTransitions

let transition = MTBounceTransition()
transition.inputImage = <from Image>
transition.destImage = <to Image>

// animate progress from 0.0 to 1.0

imageView.image = transition.outputImage

UIView Transition

let effect = MTPerlinTransition()

MTTransition.transition(with: view, effect: effect, animations: {
    // Do your animation to your view
}) { (_) in
    // Transition completed
}

UIViewController Push Transition

class PushAViewController: UIViewController {

    private let transition = MTViewControllerTransition(transition: MTBurnTransition())
    
    // ...
}

extension PushAViewController: UINavigationControllerDelegate {
    
    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        if operation == .push {
            return transition
        }
        return nil
    }
}

UIViewController Present Transition

class PresentAViewController: UIViewController {

    // ...
    
    let vc = PresentBViewController()
    vc.modalPresentationStyle = .fullScreen
    vc.transitioningDelegate = self
    present(vc, animated: true, completion: nil)
}

extension PresentAViewController: UIViewControllerTransitioningDelegate {
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return transtion
    }
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return transtion
    }
}

Video Transition

MTTransitions also support merging videos with transitions.

  • Support merge multiple video files
  • Support multiple transition effects
  • Support different multiple render size.
  • Support passthrough transition.
// pick one transtion effect
let effect = MTTransition.Effect.wipeLeft
let duration = CMTimeMakeWithSeconds(2.0, preferredTimescale: 1000)
try? videoTransition.merge(clips,
                           effect: effect,
                           transitionDuration: duration) { [weak self] result in

    guard let self = self else { return }
    let playerItem = AVPlayerItem(asset: result.composition)
    playerItem.videoComposition = result.videoComposition
    
    self.player.seek(to: .zero)
    self.player.replaceCurrentItem(with: playerItem)
    self.player.play()
}

Please refer VideoTransitionSampleViewController and MultipleVideoTransitionsViewController for more details.

Create Video From Images

MTMovieMaker support create video from a sequence images with transitions. You can also pass a local audio file url to MTMovieMaker to create background music.

let fileURL = URL(fileURLWithPath: path)
movieMaker = MTMovieMaker(outputURL: fileURL)
do {
    try MTMovieMaker?.createVideo(with: images, effects: effects) { result in
        switch result {
        case .success(let url):
            print(url)
        case .failure(let error):
            print(error)
        }
    }
} catch {
    print(error)
}