Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private func popUp(index: Int) {
- var size = CGSize()
- let imageSize: CGFloat = 75
- if UIDevice.current.userInterfaceIdiom == .pad
- {
- size = CGSize(width: 330, height: 240)
- }
- else
- {
- size = CGSize(width: self.view.frame.width * 0.87, height: 225)
- }
- let mainView = UIView(frame: .zero)
- mainView.backgroundColor = .white
- mainView.translatesAutoresizingMaskIntoConstraints = false
- mainView.layer.cornerRadius = 8
- mainView.isUserInteractionEnabled = true
- mainView.clipsToBounds = true
- mainView.layer.zPosition = 5
- mainView.transform = CGAffineTransform(scaleX: 0, y: 0)
- guard !background.isDescendant(of: self.view) else {
- return
- }
- background.backgroundColor = UIColor(white: 0.1, alpha: 0.37)
- background.layer.zPosition = 4
- background.isUserInteractionEnabled = false
- background.translatesAutoresizingMaskIntoConstraints = false
- let colorView = UIView(frame: .zero)
- colorView.backgroundColor = .blueColor
- colorView.translatesAutoresizingMaskIntoConstraints = false
- let image = UIImageView(frame: .zero)
- image.contentMode = .scaleAspectFill
- image.translatesAutoresizingMaskIntoConstraints = false
- if requests[index].image != nil && requests[index].image != "" {
- image.loadImageUsingCache(withUrl: requests[index].image)
- } else {
- image.image = UIImage(named: "avatar")
- }
- let nameLbl = UILabel(frame: .zero)
- nameLbl.font = UIFont.systemFont(ofSize: 22, weight: .regular)
- nameLbl.translatesAutoresizingMaskIntoConstraints = false
- nameLbl.text = requests[index].username
- let subjLbl = UILabel(frame: .zero)
- subjLbl.font = UIFont.systemFont(ofSize: 19)
- subjLbl.textColor = .lightGray
- subjLbl.translatesAutoresizingMaskIntoConstraints = false
- subjLbl.text = requests[index].subject_name
- let stdLbl = UILabel(frame: .zero)
- stdLbl.textColor = .lightGray
- stdLbl.font = UIFont.systemFont(ofSize: 19)
- stdLbl.translatesAutoresizingMaskIntoConstraints = false
- stdLbl.text = "Std - \(requests[index].standard)"
- let addressLbl = UILabel(frame: .zero)
- addressLbl.textColor = .lightGray
- addressLbl.numberOfLines = 2
- addressLbl.font = UIFont.systemFont(ofSize: 19)
- addressLbl.translatesAutoresizingMaskIntoConstraints = false
- addressLbl.text = requests[index].location ?? ""
- let acceptBut = UIButton(frame: .zero)
- acceptBut.backgroundColor = #colorLiteral(red: 0.4500938654, green: 0.9813225865, blue: 0.4743030667, alpha: 1)
- acceptBut.setTitleColor(#colorLiteral(red: 0.2106181933, green: 0.4906361527, blue: 0.5, alpha: 1), for: .normal)
- acceptBut.setTitle("Accept", for: .normal)
- acceptBut.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)
- acceptBut.layer.cornerRadius = 6
- acceptBut.translatesAutoresizingMaskIntoConstraints = false
- acceptBut.addAction(UIAction(handler: { (act) in
- hideView()
- let but = UIButton()
- but.tag = index
- self.acceptAction(sender: but)
- }) , for: .touchUpInside)
- let crossBut = UIButton(frame: .zero)
- let butImg = UIImage(systemName: "xmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 20, weight: .light))
- crossBut.translatesAutoresizingMaskIntoConstraints = false
- crossBut.setImage(butImg, for: .normal)
- crossBut.tintColor = .lightGray
- crossBut.addAction( UIAction(handler: { (act) in
- hideView()
- }) , for: .touchUpInside)
- self.view.addSubview(mainView)
- self.view.addSubview(background)
- mainView.addSubview(image)
- mainView.addSubview(nameLbl)
- mainView.addSubview(subjLbl)
- mainView.addSubview(stdLbl)
- mainView.addSubview(addressLbl)
- mainView.addSubview(colorView)
- mainView.addSubview(acceptBut)
- mainView.addSubview(crossBut)
- mainView.heightAnchor.constraint(equalToConstant: size.height).isActive = true
- mainView.widthAnchor.constraint(equalToConstant: size.width).isActive = true
- mainView.centerXAnchor.constraint(equalToSystemSpacingAfter: self.view.centerXAnchor, multiplier: 0).isActive = true
- mainView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: -100).isActive = true
- background.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
- background.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
- background.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
- background.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
- image.heightAnchor.constraint(equalToConstant: imageSize).isActive = true
- image.widthAnchor.constraint(equalToConstant: imageSize).isActive = true
- image.centerYAnchor.constraint(equalToSystemSpacingBelow: mainView.centerYAnchor, multiplier: 0).isActive = true
- image.leadingAnchor.constraint(equalTo: mainView.leadingAnchor, constant: 20).isActive = true
- image.layer.masksToBounds = true
- image.layer.cornerRadius = imageSize / 2
- stdLbl.heightAnchor.constraint(equalToConstant: 25).isActive = true
- stdLbl.centerYAnchor.constraint(equalTo: image.centerYAnchor, constant: 0).isActive = true
- stdLbl.leadingAnchor.constraint(equalTo: image.trailingAnchor, constant: 15).isActive = true
- stdLbl.trailingAnchor.constraint(greaterThanOrEqualTo: mainView.trailingAnchor, constant: 5).isActive = true
- nameLbl.leadingAnchor.constraint(equalTo: image.trailingAnchor, constant: 15).isActive = true
- nameLbl.heightAnchor.constraint(equalToConstant: 25).isActive = true
- nameLbl.trailingAnchor.constraint(greaterThanOrEqualTo: mainView.trailingAnchor, constant: 5).isActive = true
- nameLbl.bottomAnchor.constraint(equalTo: subjLbl.topAnchor, constant: -8).isActive = true
- subjLbl.leadingAnchor.constraint(equalTo: image.trailingAnchor, constant: 15).isActive = true
- subjLbl.heightAnchor.constraint(equalToConstant: 25).isActive = true
- subjLbl.trailingAnchor.constraint(greaterThanOrEqualTo: mainView.trailingAnchor, constant: 15).isActive = true
- subjLbl.bottomAnchor.constraint(equalTo: stdLbl.topAnchor, constant: -8).isActive = true
- addressLbl.heightAnchor.constraint(equalToConstant: 50).isActive = true
- addressLbl.leadingAnchor.constraint(equalTo: image.trailingAnchor, constant: 15).isActive = true
- addressLbl.trailingAnchor.constraint(lessThanOrEqualTo: mainView.trailingAnchor, constant: 10).isActive = true
- addressLbl.topAnchor.constraint(equalTo: stdLbl.bottomAnchor, constant: 8).isActive = true
- colorView.heightAnchor.constraint(equalToConstant: 7.5).isActive = true
- colorView.topAnchor.constraint(equalTo: mainView.topAnchor).isActive = true
- colorView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor).isActive = true
- colorView.trailingAnchor.constraint(equalTo: mainView.trailingAnchor).isActive = true
- acceptBut.heightAnchor.constraint(equalToConstant: 35).isActive = true
- acceptBut.widthAnchor.constraint(equalToConstant: 80).isActive = true
- acceptBut.bottomAnchor.constraint(equalTo: mainView.bottomAnchor, constant: -8).isActive = true
- acceptBut.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: -14).isActive = true
- crossBut.heightAnchor.constraint(equalToConstant: 35).isActive = true
- crossBut.widthAnchor.constraint(equalToConstant: 35).isActive = true
- crossBut.topAnchor.constraint(equalTo: colorView.bottomAnchor, constant: 0).isActive = true
- crossBut.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: 0).isActive = true
- UIView.animateKeyframes(withDuration: 0.9, delay: 0, options: .layoutSubviews)
- {
- UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/1.3)
- {
- mainView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
- }
- UIView.addKeyframe(withRelativeStartTime: 1/3, relativeDuration: 1/3)
- {
- mainView.transform = .identity
- }
- }
- completion: { (animation) in
- print("Animation Done!")
- }
- func hideView() {
- // Call hide animation here
- UIView.animateKeyframes(withDuration: 0.7, delay: 0, options: .layoutSubviews)
- {
- UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/3)
- {
- mainView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
- }
- UIView.addKeyframe(withRelativeStartTime: 1/1.3, relativeDuration: 1/1.3)
- {
- mainView.transform = CGAffineTransform(scaleX: 0, y: 0)
- }
- } completion:
- { (animation) in
- mainView.removeFromSuperview()
- self.background.removeFromSuperview()
- mainView.transform = .identity
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement