Created
August 24, 2016 08:57
-
-
Save RyogaK/9270b5ea5bc1142f9735da717333d9aa to your computer and use it in GitHub Desktop.
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
// | |
// AlertHasHeaderController.swift | |
// | |
// Created by Ryoga Kitagawa on 8/24/16. | |
// Copyright © 2016 Ryoga Kitagawa. All rights reserved. | |
// | |
import UIKit | |
final class AlertHasHeaderController: UIAlertController { | |
private weak var headerView: UIView? | |
override func viewWillDisappear(animated: Bool) { | |
super.viewWillDisappear(animated) | |
guard let headerView = headerView else { | |
return | |
} | |
UIView.animateWithDuration(0.1) { | |
headerView.alpha = 0 | |
} | |
} | |
} | |
extension AlertHasHeaderController { | |
func setHeaderView(view: UIView) { | |
headerView = view | |
view.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(view) | |
let views = ["view": view, "alertView": self.view] | |
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[view]-8-[alertView]", options: [], metrics: nil, views: views)) | |
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: [], metrics: nil, views: views)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment