小编Lev*_*i K的帖子

iOS iMessage扩展截图检测

请使用Swift 4+

注意:我在iMessage扩展程序而不是标准iMessage视图中时正在检测屏幕截图。

更新-我想出了一个可行的解决方案,每隔0.3秒左右在敏感信息周期内检查一次照片库,以检查是否添加了新的屏幕截图。如果用户未授予照片库许可,则在他们启用照片库之前,不会向他们显示内容。但是,我仍在寻找其他创新解决方案,这些解决方案不一定涉及如此繁琐的过程。

我有一个iMessage扩展名,我正在尝试检测屏幕截图。我已经尝试过在网上找到的每个观察者,由于某种原因,它没有注册屏幕截图。

ViewWillAppear()

UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
Run Code Online (Sandbox Code Playgroud)

观察者

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
    if (keyPath == "captured") {
        let isCaptured = UIScreen.main.isCaptured
        print(isCaptured)
        screenshot()
        //screenshot() sends a message alerting the message was screens hotted. However, the print statement didn't even run.
    }
}
Run Code Online (Sandbox Code Playgroud)

ViewWillDisappear()

UIScreen.main.removeObserver(self, forKeyPath: "captured", context: nil)
Run Code Online (Sandbox Code Playgroud)

我还尝试了标准的默认通知中心

let mainQueue = OperationQueue.main
    NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
        // executes …
Run Code Online (Sandbox Code Playgroud)

nsnotificationcenter ios imessage swift imessage-extension

15
推荐指数
1
解决办法
265
查看次数

如何在Swift 4中创建文本字段填充?

我有一个名为的文本域

nameTextField
Run Code Online (Sandbox Code Playgroud)

我用圆角磨圆了

nameTexfield.layer.cornerRadius = 5
Run Code Online (Sandbox Code Playgroud)

现在,文本字段中的文本触及左侧.我想在文本和边框之间创建填充.我发现的每个帖子都使用cgRect,但Swift不再支持它.如果你能搞清楚,请提供正确的代码,如果可以,请解释答案.我很感激帮助!我还需要知道在有代码的地方放置代码.

uitextfield ios swift

8
推荐指数
3
解决办法
1万
查看次数