ios - 如何在 Swift 4 中使用启动屏幕或图像来阻止 secret 信息?

标签 ios iphone swift xcode

<分区>

当应用程序移至后台时,如何通过启动图像屏蔽 View 来隐藏我的应用程序中的 secret 信息?我正在使用 Swift 和 iOS 11 创建应用程序。

下面是其他人在旧版 Swift 的 App Delegate 中使用的东西,但我不明白为什么 if on 在当前版本上工作:

- (void)applicationDidEnterBackground:(UIApplication *)application
{

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];

    imageView.tag = 101;    // Give some decent tagvalue or keep a reference of imageView in self
//    imageView.backgroundColor = [UIColor redColor];
    [imageView setImage:[UIImage imageNamed:@"Default.png"]];   // assuming Default.png is your splash image's name

    [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}

最佳答案

目前你的代码在 Objective-c 中而不是 swift 中,你可以在 swift 中尝试

func applicationDidEnterBackground(_ application: UIApplication) {

    let im = UIImageView()

    im.tag = 12

    im.frame = (self.window?.frame)!

    im.image = UIImage.init(named: "add.png")

    application.keyWindow?.subviews.last?.addSubview(im)               
}

func applicationWillEnterForeground(_ application: UIApplication) {

    if let sub = application.keyWindow?.subviews.last
    {
        for vv in sub.subviews
        {
            if(vv.tag == 12)
            {
                vv.removeFromSuperview()
            }

        }

    }

}

关于ios - 如何在 Swift 4 中使用启动屏幕或图像来阻止 secret 信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49520639/

相关文章:

javascript - MRAID 合规性

ios - 在 Swift 3 中将元数据添加到 AVPlayerItem

Android -> iOS 密码迁移

ios - 使用自定义后退按钮后导航标题消失

ios - 从 UITabBarController 初始化 viewController

ios - 如何检查 Swift 中的 3 个字符串是否相等?

ios - 我可以使用 Alamofire 检查 HTTP 服务器 URL 端点的可达性吗?

ios - 如何将 UICollectionViewCell 嵌套在另一个 UICollectionViewCell 中?

iphone - [NSSet allObjects] 每次都会返回一个顺序相同的数组吗?

iphone - 使用 NSMutableArray 将 NSDictionary 保存为 NSUserDefaults 的值