2

在我的 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)
4

1 回答 1

1

这可以通过本机 UIAlertController 实现,如下所示:-

  1. 创建类型变量UIAlertAction
  2. 设置enabled为假
  3. 当您滚动到底部时,您可以在滚动视图委托或任何自定义方式上进行检查,然后将其设置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)
于 2016-08-09T12:23:10.783 回答