Swift,在自定义 activity 指示器中添加导航控制器

Swift, Add a navigation controller in custom activity indicator

我的自定义 Activity 指示器没有与导航控制器重叠。

下面是我的代码

     func showActivityIndicator(uiView: UIView) {
        container.frame = uiView.frame
        container.center = uiView.center
        container.backgroundColor = UIColorFromHex(0xffffff, alpha: 0.1)

         var loadingView: UIView = UIView()
         loadingView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
        loadingView.center = uiView.center
        loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.5)
        loadingView.clipsToBounds = true
        loadingView.layer.cornerRadius = 10

        var imageData = NSData(contentsOfURL: NSBundle.mainBundle()
        .URLForResource("synch-loader", withExtension: "gif")!)
        let try = UIImage.animatedImageWithData(imageData!)
        var imageView = UIImageView(image: try)

        imageView.center = uiView.center
        imageView.frame = CGRect(x: uiView.frame.width/4, y: uiView.frame.height/2, width: 500, height: 15)

        loadingView.addSubview(imageView)
        container.addSubview(loadingView)
        uiView.addSubview(container)
        actInd.startAnimating()

    }

    func navigationHandling()
     {
              if self.navigationController != nil {
             self.navigationController?.navigationBar.tintColor = utility.uicolorFromHex(0x70B420)
            self.navigationController?.navigationBar.barTintColor = utility.uicolorFromHex(0x70B420)
           self.navigationController?.navigationBarHidden = false
            self.navigationItem.hidesBackButton = true

    }
         sortingBtn = UIBarButtonItem(image: sortingImg,  style: UIBarButtonItemStyle.Done, target: self, action: Selector("sortingPressed:"))

          menuBtn = UIBarButtonItem(image: menuImg,  style: UIBarButtonItemStyle.Plain, target: self, action : nil)
          sortingBtn.tintColor = UIColor.whiteColor()
          menuBtn.tintColor = UIColor.whiteColor()
          var buttons : NSArray = [menuBtn,sortingBtn]
          self.navigationItem.rightBarButtonItems = buttons as [AnyObject]
         self.navigationItem.setRightBarButtonItems([menuBtn,sortingBtn], animated: true)
          networkLabel.hidden = true

}

我只是想在导航控制器上重叠视图,这样它看起来就不会难看。

感谢帮助!

let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
let window = appDelegate?.window
window.addSubview("yourActivityIndicator")

此处将activity指标添加到window,或将window作为视图传入。

let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
let window = appDelegate?.window
showActivityIndicator(window)

您作为参数传递给此方法的 uiView

func showActivityIndicator(uiView: UIView)

是你的ViewController的视图还是你的UINavigationController的视图? 因为如果它是您的 UIViewController 视图,您的自定义加载将采用它的大小和原点,即在您的 NavigationBar