inputAccessoryView not getting touch events on iPhone X












0















I have a view that I assign as the inputAccessoryView of my view controller. I adjusted the constraints so that it's above the home indicator on iPhone X (X, XR, XS, XS Max). I keep that inputAccessoryView pinned to the bottom of the screen when the keyboard is hidden by setting canBecomeFirstResponder to true in my view controller.



It works on all phones except for the X family. On all of the X phones, my view is not getting any touch events - they are hitting the view below it, as if inputAccessoryView wasn't there.



Tapping any of the buttons inside inputAccessoryView won't work



If I constrain the bottom to superview instead of safeArea, it works, but then it's too close to the home indicator, which I don't want:



inputAccessoryView is too close to the home indicator



In this radar ("inputAccessoryViews should respect safe area inset with external keyboard on iPhone X"), Apple engineers say that this is not a bug and that developers should constrain one of the views to its parent's safeAreaLayoutGuide:




Engineering has provided the following feedback regarding this issue: It’s your responsibility to respect the input accessory view’s safeAreaInsets. We designed it this way so developers could provide a background view (i.e., see Safari’s Find on Page input accessory view) and lay out the content view with respect to safeAreaInsets. This is fairly straightforward to accomplish. Have a view hierarchy where you have a container view and a content view. The container view can have a background color or a background view that encompasses its entire bounds, and it lays out it’s content view based on safeAreaInsets. If you’re using autolayout, this is as simple as setting the content view’s bottomAnchor to be equal to it’s superview’s safeAreaLayoutGuide.




I believe that's exactly what I'm doing, but I'm clearly missing something since it breaks on X.



GitHub project is here: https://github.com/nambatee/HorizontallyScrollableToolbarAccessoryView/tree/master/Horizontally%20Scrollable%20Toolbar%20Accessory%20View










share|improve this question



























    0















    I have a view that I assign as the inputAccessoryView of my view controller. I adjusted the constraints so that it's above the home indicator on iPhone X (X, XR, XS, XS Max). I keep that inputAccessoryView pinned to the bottom of the screen when the keyboard is hidden by setting canBecomeFirstResponder to true in my view controller.



    It works on all phones except for the X family. On all of the X phones, my view is not getting any touch events - they are hitting the view below it, as if inputAccessoryView wasn't there.



    Tapping any of the buttons inside inputAccessoryView won't work



    If I constrain the bottom to superview instead of safeArea, it works, but then it's too close to the home indicator, which I don't want:



    inputAccessoryView is too close to the home indicator



    In this radar ("inputAccessoryViews should respect safe area inset with external keyboard on iPhone X"), Apple engineers say that this is not a bug and that developers should constrain one of the views to its parent's safeAreaLayoutGuide:




    Engineering has provided the following feedback regarding this issue: It’s your responsibility to respect the input accessory view’s safeAreaInsets. We designed it this way so developers could provide a background view (i.e., see Safari’s Find on Page input accessory view) and lay out the content view with respect to safeAreaInsets. This is fairly straightforward to accomplish. Have a view hierarchy where you have a container view and a content view. The container view can have a background color or a background view that encompasses its entire bounds, and it lays out it’s content view based on safeAreaInsets. If you’re using autolayout, this is as simple as setting the content view’s bottomAnchor to be equal to it’s superview’s safeAreaLayoutGuide.




    I believe that's exactly what I'm doing, but I'm clearly missing something since it breaks on X.



    GitHub project is here: https://github.com/nambatee/HorizontallyScrollableToolbarAccessoryView/tree/master/Horizontally%20Scrollable%20Toolbar%20Accessory%20View










    share|improve this question

























      0












      0








      0








      I have a view that I assign as the inputAccessoryView of my view controller. I adjusted the constraints so that it's above the home indicator on iPhone X (X, XR, XS, XS Max). I keep that inputAccessoryView pinned to the bottom of the screen when the keyboard is hidden by setting canBecomeFirstResponder to true in my view controller.



      It works on all phones except for the X family. On all of the X phones, my view is not getting any touch events - they are hitting the view below it, as if inputAccessoryView wasn't there.



      Tapping any of the buttons inside inputAccessoryView won't work



      If I constrain the bottom to superview instead of safeArea, it works, but then it's too close to the home indicator, which I don't want:



      inputAccessoryView is too close to the home indicator



      In this radar ("inputAccessoryViews should respect safe area inset with external keyboard on iPhone X"), Apple engineers say that this is not a bug and that developers should constrain one of the views to its parent's safeAreaLayoutGuide:




      Engineering has provided the following feedback regarding this issue: It’s your responsibility to respect the input accessory view’s safeAreaInsets. We designed it this way so developers could provide a background view (i.e., see Safari’s Find on Page input accessory view) and lay out the content view with respect to safeAreaInsets. This is fairly straightforward to accomplish. Have a view hierarchy where you have a container view and a content view. The container view can have a background color or a background view that encompasses its entire bounds, and it lays out it’s content view based on safeAreaInsets. If you’re using autolayout, this is as simple as setting the content view’s bottomAnchor to be equal to it’s superview’s safeAreaLayoutGuide.




      I believe that's exactly what I'm doing, but I'm clearly missing something since it breaks on X.



      GitHub project is here: https://github.com/nambatee/HorizontallyScrollableToolbarAccessoryView/tree/master/Horizontally%20Scrollable%20Toolbar%20Accessory%20View










      share|improve this question














      I have a view that I assign as the inputAccessoryView of my view controller. I adjusted the constraints so that it's above the home indicator on iPhone X (X, XR, XS, XS Max). I keep that inputAccessoryView pinned to the bottom of the screen when the keyboard is hidden by setting canBecomeFirstResponder to true in my view controller.



      It works on all phones except for the X family. On all of the X phones, my view is not getting any touch events - they are hitting the view below it, as if inputAccessoryView wasn't there.



      Tapping any of the buttons inside inputAccessoryView won't work



      If I constrain the bottom to superview instead of safeArea, it works, but then it's too close to the home indicator, which I don't want:



      inputAccessoryView is too close to the home indicator



      In this radar ("inputAccessoryViews should respect safe area inset with external keyboard on iPhone X"), Apple engineers say that this is not a bug and that developers should constrain one of the views to its parent's safeAreaLayoutGuide:




      Engineering has provided the following feedback regarding this issue: It’s your responsibility to respect the input accessory view’s safeAreaInsets. We designed it this way so developers could provide a background view (i.e., see Safari’s Find on Page input accessory view) and lay out the content view with respect to safeAreaInsets. This is fairly straightforward to accomplish. Have a view hierarchy where you have a container view and a content view. The container view can have a background color or a background view that encompasses its entire bounds, and it lays out it’s content view based on safeAreaInsets. If you’re using autolayout, this is as simple as setting the content view’s bottomAnchor to be equal to it’s superview’s safeAreaLayoutGuide.




      I believe that's exactly what I'm doing, but I'm clearly missing something since it breaks on X.



      GitHub project is here: https://github.com/nambatee/HorizontallyScrollableToolbarAccessoryView/tree/master/Horizontally%20Scrollable%20Toolbar%20Accessory%20View







      ios autolayout iphone-x safearealayoutguide inputaccessoryview






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '18 at 20:05









      nambateenambatee

      406715




      406715
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Your problem is actually is that you are not setting a height for inputAccessoryView and your scrollView is out of bounds that's why you are not getting the touch events and just to prove that if you go to your top level view and set it to clips to bounds and run your project this is what you get
          sample



          So why is this happening? it's because you view is not having an intrinsicContentSize you can give it an intrinsicContentSize by subclassing UIView and override intrinsicContentSize and return what ever width and height you want just like this



          class CustomView: UIView {
          override var intrinsicContentSize: CGSize {
          return CGSize.zero
          }
          }


          Don't forget to set your view to be CustomView in code and in the nib file



          private lazy var horizontallyScrollableToolbarAccessoryView: CustomView? = {
          let nibName = "HorizontallyScrollableToolbarAccessoryView"
          let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)?.first as? CustomView
          return view
          }()


          you can also provide the height through a height constraint like this



          override func viewDidLoad() {
          super.viewDidLoad()
          self.horizontallyScrollableToolbarAccessoryView?.heightAnchor.constraint(equalToConstant: 80).isActive = true
          }


          but you will still need to set your intrinsicContentSize to be CGSize.Zero



          class CustomView: UIView {
          override var intrinsicContentSize: CGSize {
          return CGSize.zero
          }
          }


          and that's what you get at the end a working scrollView



          sample 2






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364931%2finputaccessoryview-not-getting-touch-events-on-iphone-x%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Your problem is actually is that you are not setting a height for inputAccessoryView and your scrollView is out of bounds that's why you are not getting the touch events and just to prove that if you go to your top level view and set it to clips to bounds and run your project this is what you get
            sample



            So why is this happening? it's because you view is not having an intrinsicContentSize you can give it an intrinsicContentSize by subclassing UIView and override intrinsicContentSize and return what ever width and height you want just like this



            class CustomView: UIView {
            override var intrinsicContentSize: CGSize {
            return CGSize.zero
            }
            }


            Don't forget to set your view to be CustomView in code and in the nib file



            private lazy var horizontallyScrollableToolbarAccessoryView: CustomView? = {
            let nibName = "HorizontallyScrollableToolbarAccessoryView"
            let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)?.first as? CustomView
            return view
            }()


            you can also provide the height through a height constraint like this



            override func viewDidLoad() {
            super.viewDidLoad()
            self.horizontallyScrollableToolbarAccessoryView?.heightAnchor.constraint(equalToConstant: 80).isActive = true
            }


            but you will still need to set your intrinsicContentSize to be CGSize.Zero



            class CustomView: UIView {
            override var intrinsicContentSize: CGSize {
            return CGSize.zero
            }
            }


            and that's what you get at the end a working scrollView



            sample 2






            share|improve this answer




























              0














              Your problem is actually is that you are not setting a height for inputAccessoryView and your scrollView is out of bounds that's why you are not getting the touch events and just to prove that if you go to your top level view and set it to clips to bounds and run your project this is what you get
              sample



              So why is this happening? it's because you view is not having an intrinsicContentSize you can give it an intrinsicContentSize by subclassing UIView and override intrinsicContentSize and return what ever width and height you want just like this



              class CustomView: UIView {
              override var intrinsicContentSize: CGSize {
              return CGSize.zero
              }
              }


              Don't forget to set your view to be CustomView in code and in the nib file



              private lazy var horizontallyScrollableToolbarAccessoryView: CustomView? = {
              let nibName = "HorizontallyScrollableToolbarAccessoryView"
              let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)?.first as? CustomView
              return view
              }()


              you can also provide the height through a height constraint like this



              override func viewDidLoad() {
              super.viewDidLoad()
              self.horizontallyScrollableToolbarAccessoryView?.heightAnchor.constraint(equalToConstant: 80).isActive = true
              }


              but you will still need to set your intrinsicContentSize to be CGSize.Zero



              class CustomView: UIView {
              override var intrinsicContentSize: CGSize {
              return CGSize.zero
              }
              }


              and that's what you get at the end a working scrollView



              sample 2






              share|improve this answer


























                0












                0








                0







                Your problem is actually is that you are not setting a height for inputAccessoryView and your scrollView is out of bounds that's why you are not getting the touch events and just to prove that if you go to your top level view and set it to clips to bounds and run your project this is what you get
                sample



                So why is this happening? it's because you view is not having an intrinsicContentSize you can give it an intrinsicContentSize by subclassing UIView and override intrinsicContentSize and return what ever width and height you want just like this



                class CustomView: UIView {
                override var intrinsicContentSize: CGSize {
                return CGSize.zero
                }
                }


                Don't forget to set your view to be CustomView in code and in the nib file



                private lazy var horizontallyScrollableToolbarAccessoryView: CustomView? = {
                let nibName = "HorizontallyScrollableToolbarAccessoryView"
                let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)?.first as? CustomView
                return view
                }()


                you can also provide the height through a height constraint like this



                override func viewDidLoad() {
                super.viewDidLoad()
                self.horizontallyScrollableToolbarAccessoryView?.heightAnchor.constraint(equalToConstant: 80).isActive = true
                }


                but you will still need to set your intrinsicContentSize to be CGSize.Zero



                class CustomView: UIView {
                override var intrinsicContentSize: CGSize {
                return CGSize.zero
                }
                }


                and that's what you get at the end a working scrollView



                sample 2






                share|improve this answer













                Your problem is actually is that you are not setting a height for inputAccessoryView and your scrollView is out of bounds that's why you are not getting the touch events and just to prove that if you go to your top level view and set it to clips to bounds and run your project this is what you get
                sample



                So why is this happening? it's because you view is not having an intrinsicContentSize you can give it an intrinsicContentSize by subclassing UIView and override intrinsicContentSize and return what ever width and height you want just like this



                class CustomView: UIView {
                override var intrinsicContentSize: CGSize {
                return CGSize.zero
                }
                }


                Don't forget to set your view to be CustomView in code and in the nib file



                private lazy var horizontallyScrollableToolbarAccessoryView: CustomView? = {
                let nibName = "HorizontallyScrollableToolbarAccessoryView"
                let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)?.first as? CustomView
                return view
                }()


                you can also provide the height through a height constraint like this



                override func viewDidLoad() {
                super.viewDidLoad()
                self.horizontallyScrollableToolbarAccessoryView?.heightAnchor.constraint(equalToConstant: 80).isActive = true
                }


                but you will still need to set your intrinsicContentSize to be CGSize.Zero



                class CustomView: UIView {
                override var intrinsicContentSize: CGSize {
                return CGSize.zero
                }
                }


                and that's what you get at the end a working scrollView



                sample 2







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 21 at 20:32









                Amr MohamedAmr Mohamed

                7744832




                7744832
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364931%2finputaccessoryview-not-getting-touch-events-on-iphone-x%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()