[SWIFT] I want to temporarily disable the swipe gesture of UIPageViewController


Suppose you have a View configuration like this. スクリーンショット 2020-12-14 12.48.04.png

With "UIViewController-D" displayed in the push transition from "UIViewController-C" on the UINavigationController, I want to return to "UIViewController-C" by swiping on the left edge of the screen (blue arrow). The actual operation is "UIViewController-A" is displayed (red arrow). スクリーンショット 2020-12-14 12.43.30.png Apparently, the UIPageViewController's swipe gesture is prioritized over the UINavigationController's swipe gesture ...


I was able to disable swipes by setting the UIPageViewController's dataSource to nil. When UIViewController-D was displayed, I was able to solve the problem by posting a Notification to UIPageViewController, setting the dataSource to nil, and returning it when the screen disappears.

class PageViewController: UIPageViewController {
    static let needToChangeSwipeEnabledNotification = Notification.Name("NotificationForChangeMainPageSwipeEnabled")

    override func viewDidLoad() {
        dataSource = self
            .addObserver(forName: PageViewController.needToChangeSwipeEnabledNotification,
                         object: nil,
                         queue: nil,
                         using: { [weak self] notification in
                            guard let canSwipe = notification.object as? Bool else { return }
                            self?.changeSwipeEnabled(to: canSwipe)

    private func changeSwipeEnabled(to canSwipe: Bool) {
        dataSource = canSwipe ? self : nil

class ViewController_D: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        NotificationCenter.default.post(name: PageViewController.needToChangeSwipeEnabledNotification, object: false)

    override func viewDidDisappear(_ animated: Bool) {
        NotificationCenter.default.post(name: PageViewController.needToChangeSwipeEnabledNotification, object: true)

Recommended Posts

I want to temporarily disable the swipe gesture of UIPageViewController
I want to output the day of the week
I want to var_dump the contents of the intent
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
I want to narrow down the display of docker ps
I want to understand the flow of Spring processing request parameters
The story of Collectors.groupingBy that I want to keep for posterity
I want to control the default error message of Spring Boot
I want to change the value of Attribute in Selenium of Ruby
I want to display the number of orders for today using datetime.
I want to know the JSP of the open portlet when developing Liferay
[Ruby] I want to extract only the value of the hash and only the key
I want to get the field name of the [Java] field. (Old tale tone)
I want you to use Enum # name () for the Key of SharedPreference
I want to truncate after the decimal point
I want to get the value in Ruby
[RxSwift] I want to deepen my understanding by following the definition of Observable
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to control the start / stop of servers and databases with Alexa
I want to separate the handling of call results according to the API caller (call trigger)
I want to see the contents of Request without saying four or five
I want to recursively get the superclass and interface of a certain class
I want to call a method of another class
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log
I was addicted to the record of the associated model
I tried to summarize the state transition of docker
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
I want to dark mode with the SWT app
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to simplify the log output on Android
I want to add a delete function to the comment function
[Ruby] I want to make a program that displays today's day of the week!
Rails The concept of view componentization of Rails that I want to convey to those who want to quit
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
[Rails] I want to display the link destination of link_to in a separate tab
I want to reduce the number of unnecessary queries. From considering counter_cache to introducing counter_culture.
I want to fetch another association of the parent model from the intermediate table with has_many
I want to find out which version of java the jar file I have is available
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
I want to set the conditions to be displayed in collection_check_boxes
I want to control the display of the upper management navigation bar (Control menu) in Liferay 7 / DXP
[Rails] [bootstrap] I want to change the font size responsively
I tried to summarize the basics of kotlin and java
I want to use screen sharing on the login screen on Ubuntu 18
(´-`) .. oO (I want to easily find the standard output "Hello".
I want to bring Tomcat to the server and start the application
I want to make a specific model of ActiveRecord ReadOnly
[Swift] I tried to implement the function of the vending machine
I want to call a method and count the number
I want to use the Java 8 DateTime API slowly (now)
I want to create a form to select the [Rails] category
I want to change the color of the upper control navigation bar (Control menu) in Liferay 7 / DXP
I tried to summarize the basic grammar of Ruby briefly
I was addicted to the setting of laradock + VSCode + xdebug
I want to put the JDK on my Mac PC