在我的应用程序中,我尝试通知发件人,消息已成功发送。当用户发送消息时,我想在我的 viewController 的中心点显示一个 UILabel ,其中包含有关“您的消息已发送”的信息。 2.5 秒后我想从 View 中删除这个对象。对于此操作,我使用这部分代码:
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
switch result{
case MFMailComposeResultCancelled:
print("ok")
case MFMailComposeResultFailed:
print("ok")
case MFMailComposeResultSaved:
print("ok")
case MFMailComposeResultSent:
let sentInfo = UILabel(frame: CGRect(x: 0, y: 0, width: 250, height: 50))
sentInfo.text = "Your message has been sent"
sentInfo.textAlignment = .Center
sentInfo.center = self.view.center
sentInfo.textColor = UIColor.blackColor()
sentInfo.layer.cornerRadius = 10
sentInfo.layer.backgroundColor = UIColor.whiteColor().CGColor
self.view.addSubview(sentInfo)
UIView.animateWithDuration(2.5, animations: { () -> Void in
sendedInfo.alpha = 0
}) { (b:Bool) -> Void in
sendedInfo.removeFromSuperview()
}
default:
break
}// end switch
dismissViewControllerAnimated(true, completion: nil)
}
在这种情况下,我不知道为什么发送消息后看不到通知标签。
最佳答案
像这样重新排列你的代码
dismissViewControllerAnimated(true) { () -> Void in switch result{ case MFMailComposeResultCancelled: print("ok") case MFMailComposeResultFailed: print("ok") case MFMailComposeResultSaved: print("ok") case MFMailComposeResultSent: let sentInfo = UILabel(frame: CGRect(x: 0, y: 0, width: 250, height: 50)) sentInfo.text = "Your message has been sent" sentInfo.textAlignment = .Center sentInfo.center = self.view.center sentInfo.textColor = UIColor.blackColor() sentInfo.layer.cornerRadius = 10 sentInfo.layer.backgroundColor = UIColor.whiteColor().CGColor self.view.addSubview(sentInfo) UIView.animateWithDuration(2.5, animations: { () -> Void in sentInfo.alpha = 0 }) { (b:Bool) -> Void in sentInfo.removeFromSuperview() } default: break }// end switch }
关于ios - 为什么应用程序在使用 MFMailComposeViewController 发送消息后无法将 UILabel 显示为肯定结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36034712/