2016-08-03 1 views
0

私は使用している読み込みアニメーションを簡単に実装したり変更したりできるように、関数を作成したいと思っています。私は、私が正しく必要とするすべてのものを返す方法を確かめずに、それを表示するようにしています。ここで私はそれを作成するために使用されるコードは次のとおりです。アニメーション関数を返す

 let x = (self.view.frame.size.width/2) 
     let y = (self.view.frame.size.height/2) 
     self.loadingUI = NVActivityIndicatorView(frame: CGRectMake(x, y, 100, 100)) 
     self.loadingUI.center = CGPointMake(view.frame.size.width/2, 
             view.frame.size.height/2) 
     self.loadingBackground.backgroundColor = UIColor.lightGrayColor() 
     self.loadingBackground.frame = CGRectMake(0, 0, 150, 150) 
     self.loadingBackground.center = (self.navigationController?.view.center)! 
     self.loadingBackground.layer.cornerRadius = 5 
     self.loadingBackground.layer.opacity = 0.5 
     self.navigationController?.view.addSubview(loadingBackground) 
     self.navigationController?.view.addSubview(loadingUI) 
     self.loadingUI.type = .BallRotateChase 
     self.loadingUI.color = UIColor.whiteColor() 
     self.loadingUI.startAnimation() 

は、私はアプリ全体でそれを複数の時間を使うことができるようにそれを作成します関数を記述することが可能ですか?ほとんどのものはこのカスタムアプリのナビゲーションコントローラにあります。

+0

あなたは何を作成していますか? loadingUIとloadingBackground? –

+0

はいそうです。それは私が画面上に表示するために作成する必要があるものです。 – trever

答えて

0

は、トリックをした

func loadingAnimation(loadingUI : NVActivityIndicatorView?, loadingBG : UIView, view : UIView, navController : UINavigationController) -> (NVActivityIndicatorView, UIView) { 
    var loadUI = loadingUI 
    var loadBG = loadingBG 
    let x = (view.frame.size.width/2) 
    let y = (view.frame.size.height/2) 
    loadUI = NVActivityIndicatorView(frame: CGRectMake(x, y, 100, 100)) 
    loadUI!.center = CGPointMake(view.frame.size.width/2, 
           view.frame.size.height/2) 

    loadBG.backgroundColor = UIColor.lightGrayColor() 
    loadBG.frame = CGRectMake(0, 0, 150, 150) 
    loadBG.center = navController.view.center 
    loadBG.layer.cornerRadius = 5 
    loadBG.layer.opacity = 0.5 
    navController.view.addSubview(loadBG) 
    navController.view.addSubview(loadUI!) 

    loadUI!.type = .BallRotateChase 
    loadUI!.color = UIColor.whiteColor() 
    loadUI!.startAnimation() 

    return (loadUI!, loadBG) 
} 

それを手に入れました! UIWindow:

+0

ニース!私はタフルハハを提案しようとしていた –

+0

ありがとう!私はこれまでにそれをする必要はなかった! – trever

0

は、App委任クラス VAR]ウィンドウで、その後 をポッド ポッド 'NVActivityIndi​​catorView' をインストールしますか? VAR objNVLoader = NVLoader()

class func getDelegate() -> AppDelegate 
    { 
     return UIApplication.shared.delegate as! AppDelegate 
    } 

then did finish lunch method add 
     self.window = UIWindow(frame: UIScreen.main.bounds) 

then 

func showLoader() 
    { 
     self.window?.rootViewController!.addChildViewController(objNVLoader) 
     self.window?.rootViewController!.view!.addSubview(objNVLoader.view!) 

     objNVLoader.didMove(toParentViewController: self.window?.rootViewController!) 

     objNVLoader.view.frame=Constants.kScreenBound 
     self.window?.isUserInteractionEnabled = false 
     objNVLoader.showLoader() 
    } 

    func dismissLoader(){ 
     objNVLoader.removeFromParentViewController() 
     objNVLoader.didMove(toParentViewController: nil) 
     objNVLoader.view.removeFromSuperview() 
     self.window?.isUserInteractionEnabled = true 
     objNVLoader.dismissLoader() 
    } 


then 

       AppDelegate.getDelegate().showLoader() 
         AppDelegate.getDelegate().dismissLoader() 
1

ここでは、簡単かつ簡単なバージョンです..私はのviewDidLoad内のすべてを()を添加しているが、あなたはこれの世話をするために、新しい別々の機能を作ることができます。

デフォルトのローダータイプをballClipRotateMultipleに変更し、デフォルトの色を青に変更しました。荷物の色も白であるので、bgの色やローダーの色を変えてください。

import NVActivityIndicatorView 

class ViewController: UIViewController, NVActivityIndicatorViewable { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    let x = self.view.center.x 
    let y = self.view.center.y 

    let frame = CGRect(x: (x - 50), y: (y - 50), width: 100, height: 100) 
    let activityIndicatorView = NVActivityIndicatorView(frame: frame) 
    activityIndicatorView.type = .ballClipRotateMultiple 
    activityIndicatorView.color = UIColor.blue 

    self.view.addSubview(activityIndicatorView) 
    activityIndicatorView.startAnimating() 
    } 
}