如果没有网络,任何最佳做法,如何阻止ios swift?

时间:2016-01-29 13:51:26

标签: ios swift user-interface

我想在没有网络连接的情况下阻止我的应用程序的用户界面。

我该怎么做?

创建阻挡宽屏幕透明视图

在需要阻止ui触摸时将其移到前面?

当网络回来时将它移到后面?

对于快速实施的备份,是否有最好的用户体验实践?

3 个答案:

答案 0 :(得分:2)

您可以只禁用该特定视图的用户交互,而不是完成所有操作。如下所示

[self.view setUserInteractionEnabled:NO];
self.view.userInteractionEnabled = false //swift implementation

这将禁用该视图的所有子视图的用户交互

答案 1 :(得分:2)

如果处理互联网连接的代码不在当前显示的视图控制器

UIApplication.sharedApplication().keyWindow.rootViewController.view.userInteractionEnabled = false

答案 2 :(得分:1)

这不理想但我有基于Nanayakkara project的解决方案。 AppDelegate会在MyConnectionManager选择器上显示networkStatusChanged

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("networkStatusChanged:"), name: ReachabilityStatusChangedNotification, object: nil)
Reach().monitorReachabilityChanges()

每次更改连接状态时,管理员都会调用networkStatusChanged并检查连接是否丢失&顶视图不是特殊的连接视图,其中包含“请检查您的互联网连接”等消息。如果不是经理从sharedApplication

检索topController
func topController() -> UIViewController? {
    if var topRootController =
        UIApplication.sharedApplication().keyWindow?.rootViewController {
            while((topRootController.presentedViewController) != nil) {
                topRootController = topRootController.presentedViewController!
            }
            return topRootController
        }
        return nil
    }

并使用presentViewController调用ConnectionViewController

相关问题