ios - Swift 的事件指示器仅覆盖部分屏幕

标签 ios xcode swift uiactivityindicatorview

我正在尝试使用覆盖整个屏幕的背景来制作事件指示器。我的问题是,当我运行该应用程序时,它只覆盖了屏幕的一部分。我不确定我在这里做错了什么。

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")
                }
            })
        }
    }

Display with the code above

有什么建议吗?

最佳答案

改变这一行

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/

相关文章:

ios - responseObject 不是 JSON,而是 AFHTTPRequestOperationManager 的 NSInLineData

ios - 调试时如何从命令行启动iOS应用?

ios - 如何在滑动手势识别器函数中找到 UIButton 元素的父元素以构造对象?

arrays - 没有更多上下文,表达式类型不明确

iOS - 如何在 Objective C 的 XCUITest 上实现点击按钮

ios - 无法从应用程序文档文件夹中删除文件

javascript - Trigger.IO 如何使用 javascript 找出设备类型

ios - 如何修复警告 : Incompatible pointer types assigning to 'NSMutableString *' from 'NSString *'

ios - 如何防止 `pod install` 在不创建新目标的情况下将 libPods.a 添加到 "Link binary with Libraries"构建阶段?

ios - UITableView 单元格的动态高度问题(Swift)