在swfit中为UIAlertView摇动动画

时间:2015-11-07 01:01:48

标签: animation swift2 uialertview ios9.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)

}

1 个答案:

答案 0 :(得分:0)

在接受的答案中查看this threadconverting代码,以下是我的内容:

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)

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