swift - 在 Swift 中制定隐私政策 : How to make UIAlertController action button disabled until message is scrolled to the bottom

标签 swift uialertcontroller uialertaction

在我的 iOS 应用程序中,我尝试使用 UIAlertController 实现一个简单的隐私策略。根据法律,该政策在被接受之前必须是可滚动的——就像当今大多数隐私政策一样。

根据我自己的研究,我发现您可以禁用和启用 UIAlertAction 按钮,但我不知道如何识别 UIAlertController 消息正文何时滚动。一直滚动到底部可能是一项要求,我有兴趣找出一种同样可行的方法。

UIAlertController

这是我当前为上面的默认外观 UIAlertController 编写的代码。

let alertController = UIAlertController(title: "Privacy Policy", message: privacyPolicyString, preferredStyle: UIAlertControllerStyle.Alert)

let AcceptAction = UIAlertAction(title: "Accept", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction) -> Void in

    //perform next step in login verification
})

let DeclineAction = UIAlertAction(title: "Decline", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction) -> Void in

    //User has declined privacy policy. The view resets to standard login state
})

alertController.addAction(AcceptAction)
alertController.addAction(DeclineAction)

self.presentViewController(alertController, animated: true, completion: nil)

最佳答案

这可以通过原生 UIAlertController 实现,如下所示:-

  1. 创建类型为UIAlertAction的变量
  2. enabled设置为false
  3. 当你滚动到底部时,你可以在 ScrollView 委托(delegate)或任何自定义方式上检查它,然后将 enabled 设置为 true
  4. 下面代码中最重要的是:-

    self.actionToEnable = action
    action.enabled = false
    

代码引用:-

weak var actionToEnable : UIAlertAction?

func callbackWhenScrollToBottom(sender:UIScrollView) {
    self.actionToEnable?.enabled = true
}

       let alert = UIAlertController(title: "Title", message: "Long text here", preferredStyle: UIAlertControllerStyle.Alert)
        let cancel = UIAlertAction(title: "Accept", style: UIAlertActionStyle.Cancel, handler: { (_) -> Void in

        })

        let action = UIAlertAction(title: "Decline", style: UIAlertActionStyle.Default, handler: { (_) -> Void in

        })

        alert.addAction(cancel)
        alert.addAction(action)

        self.actionToEnable = action
        action.enabled = false
        self.presentViewController(alert, animated: true, completion: nil)

关于swift - 在 Swift 中制定隐私政策 : How to make UIAlertController action button disabled until message is scrolled to the bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38849118/

相关文章:

objective-c - 使用 Apple Metal 的透明窗口和 View

multithreading - iOS - 默认在哪个队列选择器上运行?

ios - Objective-C 循环比较两个文本字段的密码

ios - 如何在 UIAlertView 中显示时间?

ios - NSString 中的 Unicode 符号尺寸错误

ios - UIButton 标题标签的不同大小的字符串

ios - 如何在 Swift 中从 UIAlertAction 访问 self?

ios - 协调器模式 - 使用 Storyboard 而不是 Xib

swift - MKMapView Instruments iOS10 中的内存泄漏

swift - 如何使用 Storyboard从弹出窗口快速访问父 View Controller