Skip to content

Instantly share code, notes, and snippets.

@RyogaK
Created August 24, 2016 08:57
Show Gist options
  • Save RyogaK/9270b5ea5bc1142f9735da717333d9aa to your computer and use it in GitHub Desktop.
Save RyogaK/9270b5ea5bc1142f9735da717333d9aa to your computer and use it in GitHub Desktop.
//
// 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