Created
May 31, 2017 14:42
-
-
Save Savchukv/4492d99667648abccd09468b74899058 to your computer and use it in GitHub Desktop.
Example custom animation PopUp ViewController with sending email
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
// | |
// PopUpViewController.swift | |
// | |
// Created by Vasiliy Savchuk on 22.11.16. | |
// Copyright © 2016 All rights reserved. | |
// | |
// Usage this snippet: | |
// @IBAction func yourButtonDidPress(_ sender: Any) { | |
// let popOverVC = UIStoryboard(name: Constants.Storyboard.Map, bundle: nil).instantiateViewController(withIdentifier: Constants.StoryboardID.PopUpViewController) as! PopUpViewController | |
// popOverVC.pointModel = self.curentPoint | |
// self.addChildViewController(popOverVC) | |
// popOverVC.view.frame = self.view.frame | |
// self.view.addSubview(popOverVC.view) | |
// popOverVC.didMove(toParentViewController: self) | |
// } | |
import UIKit | |
import MessageUI | |
class PopUpViewController: UIViewController { | |
@IBOutlet weak var pinButton: UIButton! | |
@IBOutlet weak var titleLabel: UILabel! | |
@IBOutlet weak var recommendationTitle: UILabel! | |
//MARK - Lifecicle Object | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.4) | |
self.localizeUI() | |
self.showAnimate() | |
} | |
//Methods | |
func localizeUI() { | |
self.titleLabel.text = NSLocalizedString("Recommendation", comment: "") | |
self.pinButton.setTitle(NSLocalizedString("PIN", comment: ""), for: .normal) | |
} | |
//MARK: Actions | |
@IBAction func closePopUp(_ sender: Any) { | |
self.removeAnimate() | |
} | |
@IBAction func callButtonDidPress(_ sender: Any) { | |
if UIDevice.current.model == "iPhone" { | |
UIApplication.shared.openURL(URL(string: "tel:01800")!) | |
} else { | |
showAlert(title: "Margot", message: "Your device doesn't support this feature.") | |
} | |
} | |
@IBAction func openMail(_ sender: Any) { | |
if MFMailComposeViewController.canSendMail() { | |
let mail = MFMailComposeViewController() | |
mail.mailComposeDelegate = self | |
mail.setToRecipients(["test@test.com"]) | |
mail.setSubject("Company") | |
mail.setMessageBody("TEXT: TEST", isHTML: false) | |
present(mail, animated: true, completion: nil) | |
} else { | |
showAlert(title: "Company", message: "Your device can't support email") | |
} | |
} | |
//MARK: Methods | |
func showAnimate() | |
{ | |
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3) | |
self.view.alpha = 0.0; | |
UIView.animate(withDuration: 0.25, animations: { | |
self.view.alpha = 1.0 | |
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) | |
}); | |
} | |
func removeAnimate() | |
{ | |
UIView.animate(withDuration: 0.25, animations: { | |
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3) | |
self.view.alpha = 0.0; | |
}, completion:{(finished : Bool) in | |
if (finished) | |
{ | |
self.view.removeFromSuperview() | |
} | |
}); | |
} | |
} | |
extension PopUpViewController: MFMailComposeViewControllerDelegate { | |
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { | |
controller.dismiss(animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment