Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func showSuccessView(message: String = "Request Sent Successfully!")
- {
- var size = CGSize()
- if UIDevice.current.userInterfaceIdiom == .pad
- {
- size = CGSize(width: self.view.frame.width / 3, height: self.view.frame.height / 6)
- }
- else
- {
- size = CGSize(width: self.view.frame.width * 0.8, height: 205)
- }
- let successView = UIView(frame: CGRect.zero)
- successView.backgroundColor = .white
- successView.translatesAutoresizingMaskIntoConstraints = false
- successView.layer.cornerRadius = 21
- successView.layer.zPosition = 7
- successView.transform = CGAffineTransform(scaleX: 0, y: 0)
- let background = UIView(frame: .zero)
- background.backgroundColor = UIColor(white: 0.1, alpha: 0.37)
- background.layer.zPosition = 4
- background.isUserInteractionEnabled = false
- background.translatesAutoresizingMaskIntoConstraints = false
- let imageView = UIImageView(frame: CGRect.zero)
- imageView.image = UIImage(systemName: "checkmark.circle", withConfiguration: UIImage.SymbolConfiguration(weight: .thin))
- imageView.tintColor = .systemGreen
- imageView.translatesAutoresizingMaskIntoConstraints = false
- let label = UILabel(frame: CGRect.zero)
- label.text = message
- label.translatesAutoresizingMaskIntoConstraints = false
- label.textAlignment = .center
- let action = UIAction { _ in
- // Call hide animation here
- UIView.animateKeyframes(withDuration: 0.7, delay: 0, options: .layoutSubviews)
- {
- UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/3)
- {
- successView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
- }
- UIView.addKeyframe(withRelativeStartTime: 1/1.3, relativeDuration: 1/1.3)
- {
- successView.transform = CGAffineTransform(scaleX: 0, y: 0)
- }
- } completion:
- { (animation) in
- successView.removeFromSuperview()
- background.removeFromSuperview()
- successView.transform = .identity
- }
- }
- let cancelButton = UIButton(frame: CGRect.zero)
- cancelButton.setImage(UIImage(systemName: "xmark")?.applyingSymbolConfiguration(.init(pointSize: 22)), for: .normal)
- cancelButton.tintColor = #colorLiteral(red: 0.8374180198, green: 0.8374378085, blue: 0.8374271393, alpha: 1)
- cancelButton.addAction(action, for: .touchUpInside)
- cancelButton.translatesAutoresizingMaskIntoConstraints = false
- self.view.addSubview(successView)
- self.view.addSubview(background)
- successView.addSubview(imageView)
- successView.addSubview(label)
- successView.addSubview(cancelButton)
- successView.heightAnchor.constraint(equalToConstant: size.height).isActive = true
- successView.widthAnchor.constraint(equalToConstant: size.width).isActive = true
- successView.centerXAnchor.constraint(equalToSystemSpacingAfter: self.view.centerXAnchor, multiplier: 0).isActive = true
- successView.centerYAnchor.constraint(equalToSystemSpacingBelow: self.view.centerYAnchor, multiplier: 0).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
- cancelButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
- cancelButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
- cancelButton.topAnchor.constraint(equalTo: successView.topAnchor, constant: 8).isActive = true
- cancelButton.trailingAnchor.constraint(equalTo: successView.trailingAnchor, constant: -8).isActive = true
- label.centerXAnchor.constraint(equalTo: successView.centerXAnchor).isActive = true
- label.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 25).isActive = true
- label.heightAnchor.constraint(equalToConstant: 28).isActive = true
- label.leadingAnchor.constraint(lessThanOrEqualToSystemSpacingAfter: successView.leadingAnchor, multiplier: 5).isActive = true
- label.trailingAnchor.constraint(lessThanOrEqualToSystemSpacingAfter: successView.trailingAnchor, multiplier: 5).isActive = true
- imageView.heightAnchor.constraint(equalToConstant: 80).isActive = true
- imageView.widthAnchor.constraint(equalToConstant: 80).isActive = true
- imageView.centerXAnchor.constraint(equalToSystemSpacingAfter: successView.centerXAnchor, multiplier: 0).isActive = true
- imageView.topAnchor.constraint(equalTo: successView.topAnchor, constant: 25).isActive = true
- UIView.animateKeyframes(withDuration: 0.9, delay: 0, options: .layoutSubviews)
- {
- UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/1.3)
- {
- successView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
- }
- UIView.addKeyframe(withRelativeStartTime: 1/3, relativeDuration: 1/3)
- {
- successView.transform = .identity
- }
- }
- completion: { (animation) in
- print("Animation Done!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement