1

我知道对于 Objective-C 有一些类似的问题。有人知道如何在 Swift 中制作它吗?下面是我的alertView功能。

func alertError(errorString: String?){

    let alertController = UIAlertController(title: "Error Detected", message:
        errorString, preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,
        handler: nil))

    self.presentViewController(alertController, animated: true, completion: nil)

}
4

1 回答 1

0

查看这个线程并将代码转换为接受的答案,这就是我得到的:

var dialog: UIAlertView = UIAlertView(title: "Title", message: "Message:", delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "Done", nil)
dialog.alertViewStyle = UIAlertViewStylePlainTextInput
dialog.show()
var dillusionView: UIView = UIView(frame: CGRectMake(0, 0, view.frame.size.width, view.frame.size.height))
dillusionView.backgroundColor = UIColor.blackColor()
view.addSubview(dillusionView)

UIView(duration: 1.0, delay: 0.0, options: UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat, animations: {    UIView(relativeStartTime: 0.0, relativeDuration: 0.5, animations: { dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x - 10, dialog.frame.origin.y)

})
    UIView(relativeStartTime: 0.5, relativeDuration: 0.5, animations: { dialog.window.transform = CGAffineTransformTranslate(dialog.transform, dialog.frame.origin.x + 10, dialog.frame.origin.y)

    })

}, completion: nil)

作为警告,此代码中可能存在一些错误。希望能帮助到你!

于 2015-11-18T16:19:43.510 回答