Skip to content

Instantly share code, notes, and snippets.

View ohlulu's full-sized avatar
😎
happy test happy deliver

ohlulu ohlulu

😎
happy test happy deliver
View GitHub Profile
class CustomPresentAnimation: NSObject , UIViewControllerAnimatedTransitioning {
var startPoint: CGPoint // 擴散的起始點
private let durationTime = 0.45 // 動畫時間
init(startPoint: CGPoint) {
self.startPoint = startPoint
super.init()
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// 取出 toView, 在上面的示意圖中代表的就是 A 畫面
guard let toView = transitionContext.viewController(forKey: .to)?.view else {
return
}
// 取出 container view
let containerView = transitionContext.containerView
class CustomDismissAnimation: NSObject , UIViewControllerAnimatedTransitioning {
let endPoint: CGPoint
var grayView: UIView!
private let durationTime = 0.45
init(endPoint: CGPoint) {
self.endPoint = endPoint
super.init()
}
class PrepareToPushViewController: UIViewController {
let button = UIButton(type: .system)
let animation = CustomTransition()
override func viewDidLoad() {
super.viewDidLoad()
// set view layout
}
}
@ohlulu
ohlulu / 6.swift
Last active September 10, 2019 07:53
class CustomTransition: NSObject, UIViewControllerTransitioningDelegate {
// ...
let interaction = UpToDownIneraction()
func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return nil
}
class UpToDownIneraction: UIPercentDrivenInteractiveTransition {
var interacting: Bool = false
private var couldComplete: Bool = false
private weak var presentingViewController: UIViewController? = nil
}
class UpToDownIneraction: UIPercentDrivenInteractiveTransition {
// ...
func wireGesture(on viewController: UIViewController) {
presentingViewController = viewController
let gesture = UIPanGestureRecognizer(target: self, action: #selector(handleGesture(_:)))
viewController.view.addGestureRecognizer(gesture)
}
class UpToDownIneraction: UIPercentDrivenInteractiveTransition {
// ...
@objc func handleGesture(_ gestureRecoginizer: UIPanGestureRecognizer) {
let gestureView = gestureRecoginizer.view!
let trainsiton = gestureRecoginizer.translation(in: gestureView)
switch gestureRecoginizer.state {
case .began:
print("began")
@objc func buttonPressed() {
let vc = PresentSecondViewController()
animation.destinationPoint = button.center
vc.transitioningDelegate = animation
vc.modalPresentationStyle = .custom
animation.interaction.wireGesture(on: vc)
present(vc, animated: true, completion: nil)
}
@ohlulu
ohlulu / APIRouter_with_Alamofire.swift
Last active September 10, 2019 02:55
APIRouter Alamofire
import Foundation
import Alamofire
struct HTTPHeader {
enum Field: String {
case contentType = "Content-Type"
case acceptType = "Accept"
}