SamuraiTransition 1.1.1

SamuraiTransition 1.1.1

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最后发布2019年6月
SPM支持 SPM

hachinobu 维护。



  • 作者:
  • Takahiro Nishinobu

SamuraiTransition

SamuraiTransiton 是一个用 Swift 编写的 ViewController 切换框架。

它就像武士用剑将屏幕切成两半的动画。

切换类型

横向 纵向 对角线 交叉
horizontalzan vertical diagonally cross
横杠 锯齿形 圆形 矩形
x jagged circle rectangle
三角形 撕裂 切碎
triangle shredded chopped

用法

简单用法

// make your view controller a subclass of SamuraiViewController
// present it as normal

import SamuraiTransition

class ModalViewController: SamuraiViewController {
    //...
}

class ViewController: UIViewController {
    
    @IBAction func horizontalZan(_ sender: Any) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        present(vc, animated: true, completion: nil)
    }
    
    @IBAction func verticalZan(_ sender: Any) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        // customization
        vc.samuraiTransition.zan = .vertical
        present(vc, animated: true, completion: nil)
    }
    
    @IBAction func diagonallyZan(_ sender: Any) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        // customization
        vc.samuraiTransition.zan = .diagonally
        present(vc, animated: true, completion: nil)
    }

}

可以设置的属性

    //Time of transition
    public var duration: TimeInterval = 0.33
    //presenting or not
    public var presenting = true
    //horizontal or vertical or diagonally
    public var zan = Zan.horizontal
    //enable or disable affine processing when ModalViewcontroller appears 
    public var isAffineTransform: Bool = true
    //Passing point of the sword line
    public var zanPoint: CGPoint?
    //sword line color
    public var zanLineColor = UIColor.black
    //sword line width
    public var zanLineWidth: CGFloat = 1.0

自定义

class ViewController: UIViewController {
    
    let transition = SamuraiTransition()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        transition.duration = 1.0
        transition.zan = Zan.vertical
        transition.isAffineTransform = false
        transition.zanLineColor = .blue
        transition.zanLineWidth = 2.0
    }

    @IBAction func tapModalButton(_ sender: AnyObject) {
        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        let button = sender as! UIButton
        transition.zanPoint = CGPoint(x: button.center.x, y: button.center.y)
//        vc.transitioningDelegate = transition
        vc.transitioningDelegate = self
        present(vc, animated: true, completion: nil)
    }

}

extension ViewController: UIViewControllerTransitioningDelegate {
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition.presenting = true
        return transition
    }
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition.presenting = false
        return transition
    }
    
}

需求

  • Xcode 10 或更高版本
  • iOS 9.0 或更高版本
  • Swift 5.0

安装

CocoaPods

pod 'SamuraiTransition'

Carthage

  • 在命令行中插入 github "hachinobu/SamuraiTransition"
  • 运行 carthage update
  • Carthage/Build 中连接您的应用程序与 SamuraiTransition.framework

许可协议

SamuraiTransition 以 MIT 许可协议提供。更多信息,请参阅 LICENSE 文件。