1

I have a screen in which I have a UIPageViewController in each page I have a UIButton. The problem is that there is a delay of the pressed/highlighted state of the button for about a half second when the user presses the button. both state images are set to the button using the storyboard.

This happens in the Simulator as well as on a real device.

Now from my Google searches, I came across a few posts that describe this issue, for example:

UIButton delayed state change

and:

UIbutton only looks clicked (highlighted) on longPress?

In all posts, the solution is to use the delaysContentTouches setting and set it to false.

The problem is: I didn't found how would I apply this in my case of a UIPageViewController. most of the posts talk this issue in a UIScrollView or a UITableView.

So, the question is: how would I do that in case of a UIPageViewController? I didn't see that UIPageViewController has this setting and didn't find any other way to apply it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Emil Adz
  • 40,709
  • 36
  • 140
  • 187

1 Answers1

1

Found a solution to this issue, This piece of code will fix the button highlighted click delay but will prevent the pager scroll on the button itself.

public override func viewDidAppear(_ animated: Bool) {
    for view in self.view.subviews {
        if view is UIScrollView {
            (view as? UIScrollView)!.delaysContentTouches = false
        }
    }
}

The reason I didn't find this in UIPageViewController is that UIPageViewController is not a subclass of UIScrollView as I expected but it contains it as a subview.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187