我正在尝试使用覆盖整个屏幕的背景来制作事件指示器。我的问题是,当我运行该应用程序时,它只覆盖了屏幕的一部分。我不确定我在这里做错了什么。
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
self.dismissViewControllerAnimated(true) { () -> Void in
self.activityIndicator = UIActivityIndicatorView(frame: self.view.frame)
self.activityIndicator.backgroundColor = UIColor(white: 1.0, alpha: 0.5)
self.activityIndicator.center = self.view.center
self.activityIndicator.hidesWhenStopped = true
self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
self.view.addSubview(self.activityIndicator)
self.activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
print("save the data on to core data and onto Parse, then segue to the new input controller")
let file = PFFile(data: UIImageJPEGRepresentation(image, 1.0)!)
let insurance = PFObject(className: "Insurance")
insurance["userId"] = PFUser.currentUser()?.objectId
insurance["imageFile"] = file as PFFile
insurance.saveInBackgroundWithBlock({ (success, error ) -> Void in
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if (success) {
self.performSegueWithIdentifier("segueToDetails", sender: self)
}else{
self.displayAlert("Problems Savings", message: "There was an error with saving the data")
}
})
}
}
有什么建议吗?
最佳答案
改变这一行
self.activityIndicator = UIActivityIndicatorView(frame: self.view.frame)
到
self.activityIndicator = UIActivityIndicatorView(frame: self.view.bounds)
从您的屏幕截图来看,self.view
的框架类似于 (0, 64,/* some width */,/* some height */)
. y
原点在屏幕下方 64 点。您复制此帧并为事件指示器提供相同的帧。如果您将事件指示器添加到 y
原点为 0 点的 View 中,就会出现这种情况。由于您将其添加到的 View 已经在屏幕下方 64 点,因此将事件指示器添加到该框架将使事件指示器在手机屏幕下方 128 点处成为真实的。我通过添加 View 的 y
原点和事件指示器的 y
原点得到这个数字。
关于ios - Swift 的事件指示器仅覆盖部分屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34094897/