Swift 2:屏幕底部而不是中间的本地通知

时间:2016-02-20 22:16:22

标签: ios swift

我的应用程序在屏幕底部显示本地通知,而不是在中间,因为它们是剩余的时间。我有一张图片显示我的问题。我还附上了我的代码以供参考。我创建了一个名为displayAlert的函数,因此我不必为其他警报重复相同的代码。

有人有任何建议吗?

Picture

func displayAlert(title: String, message: String) {

    var alert = UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)
    alert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
}

@IBAction func loginButton(sender: AnyObject) {

    var seperated = emailLabel.text?.componentsSeparatedByString("@")
    let username = seperated![0]

    if emailLabel.text != "" && passwordLabel.text != ""
    {
        activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0,0,50,50))
        activityIndicator.center = self.view.center
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = .Gray
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        UIApplication.sharedApplication().beginIgnoringInteractionEvents()

        PFUser.logInWithUsernameInBackground(username, password: passwordLabel.text!, block: { (user, error) -> Void in

            self.activityIndicator.stopAnimating()
            UIApplication.sharedApplication().endIgnoringInteractionEvents()

            if user != nil
            {
                // Logged in!
                self.performSegueWithIdentifier(self.loginSegue, sender: self)
            }
            else
            {
                // Failed loggin in
                if let errorCode = error?.userInfo["error"] as? String
                {
                    self.errorMessage = errorCode
                }

                self.displayAlert("Failed Log In", message: self.errorMessage)
            }
        })

    }
    else
    {
        displayAlert("Error", message: "Please enter your email and password!")
    }
}

1 个答案:

答案 0 :(得分:1)

preferredStyle: .actionSheet更改为preferredStyle: .alert,根据文档https://developer.apple.com/reference/uikit/uialertcontroller/1620092-init

以模态方式显示