132 lines
3.9 KiB
Swift
132 lines
3.9 KiB
Swift
//
|
|
// CommonViewControllerPopUp.swift
|
|
// List
|
|
//
|
|
// Created by Saveliy Stavitsky on 7/21/20.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
private class CommonViewControllerPopUpContent: UIViewController {
|
|
|
|
@IBOutlet var freeAreaView: UIView!
|
|
@IBOutlet var titleLabel: UILabel!
|
|
@IBOutlet var stackView: UIStackView!
|
|
|
|
let titleText: String?
|
|
let contentView: UIView?
|
|
let completion: (() -> Void)?
|
|
|
|
init(title: String, view: UIView, completion: (() -> Void)? = nil) {
|
|
self.titleText = title
|
|
self.contentView = view
|
|
self.completion = completion
|
|
super.init(nibName: String(describing: type(of: self)), bundle: nil)
|
|
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
titleLabel.text = titleText
|
|
|
|
stackView.arrangedSubviews.forEach({ $0.removeFromSuperview() })
|
|
if let contentView = contentView {
|
|
stackView.addArrangedSubview(contentView)
|
|
}
|
|
|
|
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
|
|
freeAreaView.addGestureRecognizer(tap)
|
|
}
|
|
|
|
@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {
|
|
dismiss(animated: true)
|
|
// dismiss(animated: true, completion: { [weak self] in
|
|
// self?.completion?()
|
|
// })
|
|
}
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
}
|
|
|
|
/*
|
|
// MARK: - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
// Get the new view controller using segue.destination.
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
}
|
|
|
|
class CommonViewControllerViewPopUp: UIViewController {
|
|
|
|
let completion: (() -> Void)?
|
|
let subView: UIView
|
|
|
|
init(title: String? = nil, image: UIImage? = nil, description: String? = nil, view: UIView, completion: (() -> Void)? = nil) {
|
|
self.completion = completion
|
|
self.subView = view
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
if let title = title {
|
|
self.title = title
|
|
}
|
|
if let image = image {
|
|
self.image = image
|
|
}
|
|
if let description = description {
|
|
self.text = description
|
|
}
|
|
// preferredContentSize = UIScreen.main.bounds.size
|
|
// delegate = self
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
|
|
completion?()
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// subView.sizeToFit()
|
|
view.addSubview(subView)
|
|
// subView.heightAnchor.constraint(equalToConstant: 400).isActive = true
|
|
// subView.widthAnchor.constraint(equalToConstant: 390 - 24).isActive = true
|
|
subView.translatesAutoresizingMaskIntoConstraints = false
|
|
subView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
|
|
subView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
|
subView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
|
subView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
|
// view.layoutIfNeeded()
|
|
}
|
|
|
|
// override func viewDidLayoutSubviews() {
|
|
// super.viewDidLayoutSubviews()
|
|
// print(subView.frame)
|
|
// print(subView.frame)
|
|
// subView.sizeToFit()
|
|
// print(subView.frame)
|
|
// print(subView.frame)
|
|
// subView.heightAnchor.constraint(equalToConstant: subView.frameHeight).isActive = true
|
|
// view.layoutIfNeeded()
|
|
// print(subView.frame)
|
|
// print(subView.frame)
|
|
//
|
|
// }
|
|
}
|