2016-06-13 83 views
0

在我的應用程序中,我使用了一個自定義的UIActivityIndi​​cator視圖(this),它效果很好。 我有一個UITableView,我希望通過tableview上的指標加載數據。爲了解決這個問題,我創建了一個帶有背景的空視圖,當我需要啓動指標的動畫時,我只需隱藏tableview並顯示空視圖+指標。UIActivityIndi​​catorView查看對話框

結果是這樣的:

Image 1

我看到的地方,我可以使用,而不是像這樣:

Image 2

我該怎麼辦?

在此先感謝。

+0

你的意思是昏暗的背景是什麼? –

+0

'NVActivityIndi​​catorViewable'不適合你嗎? – srvv

+0

@SonLe是的我認爲這是我在尋找 – Jigen

回答

1

您可以嘗試在表視圖上添加半透明的黑色視圖,並將自定義活動指示器代碼作爲子視圖放置在黑色視圖中。

let aBlackView = UIView(frame: CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height)) 
aBlackView.backgroundColor = UIColor.blackColor() 
aBlackView.alpha = 0.75 // Change the alpha depending on how much transparency you require 

let aMainWindow = UIApplication.sharedApplication().delegate!.window 
aMainWindow!!.addSubview(aBlackView) 

/* Enter you code for NVActivityIndicatorViewable here */ 

aBlackView.addSubview(/* NVActivityIndicatorViewable */) 

一旦你與你的要求做,你可以通過調用這個代碼刪除黑色的觀點:

aBlackView.removeFromSuperview() 
1

我創建顯示屏幕的活動。我用在我的項目的每一個地方。

//ProgressBarNotification.swift

import Foundation 
import UIKit 

class ProgressBarNotification { 

internal static var strLabel = UILabel() 
internal static var messageFrame = UIView() 
internal static var activityIndicator = UIActivityIndicatorView()  

internal static func progressBarDisplayer(msg:String,indicator:Bool){ 


    let view1 = UIApplication.sharedApplication().delegate?.window!!.rootViewController?.view 

    view1?.userInteractionEnabled = false 

    strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 200, height: 50)) 
    strLabel.text = msg 
    strLabel.textColor = UIColor.whiteColor() 
    messageFrame = UIView(frame: CGRect(x: view1!.frame.midX - 90, y: view1!.frame.midY - 25 , width: 180, height: 50)) 
    messageFrame.layer.cornerRadius = 15 
    messageFrame.backgroundColor = UIColor(white: 0, alpha: 0.7) 
    if indicator { 
     activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White) 
     activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50) 
     activityIndicator.startAnimating() 
     messageFrame.addSubview(activityIndicator) 
    } 
    messageFrame.addSubview(strLabel) 
    view1!.addSubview(messageFrame) 


} 

internal static func removeProgressBar() { 

    let view1 = UIApplication.sharedApplication().delegate?.window!!.rootViewController?.view 

    _ = view1?.subviews.filter({ (view) -> Bool in 
     if view == ProgressBarNotification.messageFrame { 
      view.removeFromSuperview() 
     } 
     return false 
    }) 

    ProgressBarNotification.messageFrame.removeFromSuperview() 

    view1?.userInteractionEnabled = true 

} 

    deinit{ 

    } 
} 

使用

//To start Loader 

    ProgressBarNotification.progressBarDisplayer("Loading", indicator: true) 

    //Stop 

    ProgressBarNotification.removeProgressBar() 
相關問題