Reported center coordinate of MKMapView is 8pt off the visual center - why?











up vote
0
down vote

favorite












I have an MKMapView taking up the entire screen above the tab-bar.



On top of the map, I have added another overlay UIView which draws a dot in the center of the view. The constraints of the overlay are set to match the top, bottom, leading and trailing anchors of the map view.



But when I move the map view around, the reported center position of the map view is not the position below the dot in the center of the overlay.



To make it align, I have to apply -8 pt constant to the top and bottom constraints.



I tried looking into margins, insets etc of the map view but found nothing that looked like the number 8 on the Y axis.



let overlayYoffset: CGFloat = -8
NSLayoutConstraint.activate([
view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: overlayYoffset),
view.overlayView.bottomAnchor.constraint(equalTo: mapView.bottomAnchor, constant: overlayYoffset),


Debugging the view hierarchy also shows that the overlay view and the map view has the same size and positions on top of each other.



So what is causing this issue? Have I overlooked anything, or is it "by design" that the MKMapview is not showing its centerCoordinate in the exact center of its view?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have an MKMapView taking up the entire screen above the tab-bar.



    On top of the map, I have added another overlay UIView which draws a dot in the center of the view. The constraints of the overlay are set to match the top, bottom, leading and trailing anchors of the map view.



    But when I move the map view around, the reported center position of the map view is not the position below the dot in the center of the overlay.



    To make it align, I have to apply -8 pt constant to the top and bottom constraints.



    I tried looking into margins, insets etc of the map view but found nothing that looked like the number 8 on the Y axis.



    let overlayYoffset: CGFloat = -8
    NSLayoutConstraint.activate([
    view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: overlayYoffset),
    view.overlayView.bottomAnchor.constraint(equalTo: mapView.bottomAnchor, constant: overlayYoffset),


    Debugging the view hierarchy also shows that the overlay view and the map view has the same size and positions on top of each other.



    So what is causing this issue? Have I overlooked anything, or is it "by design" that the MKMapview is not showing its centerCoordinate in the exact center of its view?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have an MKMapView taking up the entire screen above the tab-bar.



      On top of the map, I have added another overlay UIView which draws a dot in the center of the view. The constraints of the overlay are set to match the top, bottom, leading and trailing anchors of the map view.



      But when I move the map view around, the reported center position of the map view is not the position below the dot in the center of the overlay.



      To make it align, I have to apply -8 pt constant to the top and bottom constraints.



      I tried looking into margins, insets etc of the map view but found nothing that looked like the number 8 on the Y axis.



      let overlayYoffset: CGFloat = -8
      NSLayoutConstraint.activate([
      view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: overlayYoffset),
      view.overlayView.bottomAnchor.constraint(equalTo: mapView.bottomAnchor, constant: overlayYoffset),


      Debugging the view hierarchy also shows that the overlay view and the map view has the same size and positions on top of each other.



      So what is causing this issue? Have I overlooked anything, or is it "by design" that the MKMapview is not showing its centerCoordinate in the exact center of its view?










      share|improve this question















      I have an MKMapView taking up the entire screen above the tab-bar.



      On top of the map, I have added another overlay UIView which draws a dot in the center of the view. The constraints of the overlay are set to match the top, bottom, leading and trailing anchors of the map view.



      But when I move the map view around, the reported center position of the map view is not the position below the dot in the center of the overlay.



      To make it align, I have to apply -8 pt constant to the top and bottom constraints.



      I tried looking into margins, insets etc of the map view but found nothing that looked like the number 8 on the Y axis.



      let overlayYoffset: CGFloat = -8
      NSLayoutConstraint.activate([
      view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: overlayYoffset),
      view.overlayView.bottomAnchor.constraint(equalTo: mapView.bottomAnchor, constant: overlayYoffset),


      Debugging the view hierarchy also shows that the overlay view and the map view has the same size and positions on top of each other.



      So what is causing this issue? Have I overlooked anything, or is it "by design" that the MKMapview is not showing its centerCoordinate in the exact center of its view?







      ios autolayout uikit mapkit nslayoutconstraint






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 15 hours ago

























      asked 15 hours ago









      Esben von Buchwald

      386213




      386213
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Regarding top you may need +8 instead of -8



          view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: -1 * overlayYoffset)





          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',
            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%2f53265975%2freported-center-coordinate-of-mkmapview-is-8pt-off-the-visual-center-why%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Regarding top you may need +8 instead of -8



            view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: -1 * overlayYoffset)





            share|improve this answer

























              up vote
              0
              down vote













              Regarding top you may need +8 instead of -8



              view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: -1 * overlayYoffset)





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Regarding top you may need +8 instead of -8



                view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: -1 * overlayYoffset)





                share|improve this answer












                Regarding top you may need +8 instead of -8



                view.overlayView.topAnchor.constraint(equalTo: mapView.topAnchor, constant: -1 * overlayYoffset)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 15 hours ago









                Sh_Khan

                33.4k41124




                33.4k41124






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265975%2freported-center-coordinate-of-mkmapview-is-8pt-off-the-visual-center-why%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?