我有一个简单的MFMailComposeViewController
,它出现在我现有的视图控制器上,我试图通过检测UITouches
来检查用户是否正在对此进行任何活动,但我无法记录在视图控制器上的任何UITouches
,我尝试添加另一个具有清晰颜色的视图,但这只是禁用我的邮件编辑器上的交互,请建议。
ViewController代码
import Foundation
import UIKit
import MessageUI
class ViewController: UIViewController , MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
let bounds = UIScreen.mainScreen().bounds
let width = bounds.size.width
let height = bounds.size.height
let rect = CGRect(x: 0, y: 0, width: width, height: height);
let testLayer = CustomView(frame: rect)
testLayer.backgroundColor = UIColor.clearColor()
mailComposeViewController.view.addSubview(testLayer)
}
@IBAction func sendEmailButtonTapped(sender: AnyObject) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["someone@somewhere.com"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("inside mail composer view")
}
}
CustomView的代码
import UIKit
class CustomView: UIView {
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("touches started")
}
}