ios - 为什么应用程序在使用 MFMailComposeViewController 发送消息后无法将 UILabel 显示为肯定结果

标签 ios iphone swift uilabel mfmailcomposeviewcontroller

在我的应用程序中,我尝试通知发件人,消息已成功发送。当用户发送消息时,我想在我的 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/

相关文章:

html - 如何使用Swift WKWebView加载大尺寸的html页面内容

android - 使用 iOS 键盘输入时表情符号不显示在 NSAttributedString 中,在 Android 上输入时显示

android - 离线时 FireBase Cloud Messaging (FCM) 订阅/取消订阅主题

iphone - Cocos2d - 自上而下的旋转相机 View

ios - 无法在 Swift 中使用 NSPredicate 查询日期

ios - 快速从单独的 nib 文件加载 UIViewController?

iphone - 方向改变时重新定位控件

iphone - 如何将 NSDate 发送到 soap web 服务 - .net

swift - "static let"与 "let"用于声明特定于类的常量

Swift:如何指定用于静态方法调用的候选类