This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomPresentAnimation: NSObject , UIViewControllerAnimatedTransitioning { | |
var startPoint: CGPoint // 擴散的起始點 | |
private let durationTime = 0.45 // 動畫時間 | |
init(startPoint: CGPoint) { | |
self.startPoint = startPoint | |
super.init() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { | |
// 取出 toView, 在上面的示意圖中代表的就是 A 畫面 | |
guard let toView = transitionContext.viewController(forKey: .to)?.view else { | |
return | |
} | |
// 取出 container view | |
let containerView = transitionContext.containerView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomDismissAnimation: NSObject , UIViewControllerAnimatedTransitioning { | |
let endPoint: CGPoint | |
var grayView: UIView! | |
private let durationTime = 0.45 | |
init(endPoint: CGPoint) { | |
self.endPoint = endPoint | |
super.init() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrepareToPushViewController: UIViewController { | |
let button = UIButton(type: .system) | |
let animation = CustomTransition() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// set view layout | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomTransition: NSObject, UIViewControllerTransitioningDelegate { | |
// ... | |
let interaction = UpToDownIneraction() | |
func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { | |
return nil | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpToDownIneraction: UIPercentDrivenInteractiveTransition { | |
var interacting: Bool = false | |
private var couldComplete: Bool = false | |
private weak var presentingViewController: UIViewController? = nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpToDownIneraction: UIPercentDrivenInteractiveTransition { | |
// ... | |
func wireGesture(on viewController: UIViewController) { | |
presentingViewController = viewController | |
let gesture = UIPanGestureRecognizer(target: self, action: #selector(handleGesture(_:))) | |
viewController.view.addGestureRecognizer(gesture) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire | |
struct HTTPHeader { | |
enum Field: String { | |
case contentType = "Content-Type" | |
case acceptType = "Accept" | |
} | |
OlderNewer