2

In my iOS application I am trying to implement an easy privacy policy using a UIAlertController. By law, the policy has to be scrollable before it can be accepted - like most privacy policies these days.

From my own research I have seen that you can disable and enable UIAlertAction buttons but I don't know how to identify when the UIAlertController message body has been scrolled. Scrolling all the way to the bottom may be a requirement and I am interested in figuring out a way that would work too.

UIAlertController

Here is my current code for the default looking UIAlertController above.

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)
Danoram
  • 8,132
  • 12
  • 51
  • 71
  • you need to make your own alert view for that so you will have access to offset of that view and ability to disable or enable button – Lu_ Aug 09 '16 at 11:21

1 Answers1

1

This can be possible with native UIAlertController as follows:-

  1. Create variable of type UIAlertAction
  2. Set enabled to false
  3. When you scrolled to bottom, you can check this on scroll view delegate or any custom way, then set the enabled to true
  4. The most important thing in below code is:-

    self.actionToEnable = action
    action.enabled = false
    

Code reference:-

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)
pkc456
  • 8,350
  • 38
  • 53
  • 109
  • This is a good start! Can you provide some insight into how I find the scroll offset of the alert in the callback? And where I would call that function? – Danoram Aug 12 '16 at 01:11
  • I checked the hierarchy of UIAlertController, but not able to find any scrollview, textview. Thus not able to get scroll offset. Have you find any solution. – pkc456 Aug 19 '16 at 04:33
  • No not yet unfortunately. I'm still looking into it! – Danoram Aug 20 '16 at 00:33