我无法在Swift

时间:2016-08-28 16:25:11

标签: ios swift animation uiview

我遇到的问题是我有一个不显示互联网连接的UIView。我想让它在加载视图时潜水,以免被人看到。当连接打开和关闭时,它应该弹回并离开。通知器正在工作,如果连接打开和关闭,它将移动或移除横幅。但是,当视图首次加载时,它不会使UIView移开。

 override func viewWillAppear(animated: Bool) {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.actOnSpecialNotification(_:)), name: "ReachabilityChangedNotification", object: nil)
       print("viewappeard")
        self.unableBox.center.y  -= view.bounds.height

    }


    func actOnSpecialNotification(note:NSNotification){
        let reachability = note.object as! Reachability

        if reachability.isReachable() {
            self.unableBox.center.y  -= view.bounds.height
            print(self.unableBox.center.y)
            print(view.bounds.height)
            if reachability.isReachableViaWiFi() {
                print("Reachable via WiFi")
            } else {
                print("Reachable via Cellular")
            }
        } else {
            self.unableBox.center.y  = view.bounds.height/2
            print(self.unableBox.center.y)
            print(view.bounds.height)
            print("Network not reachable")
        }



        }

0 个答案:

没有答案