{"action":"created","issue":{"url":"https://api.github.com/repos/motion-kit/motion-kit/issues/102","labels_url":"https://api.github.com/repos/motion-kit/motion-kit/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/motion-kit/motion-kit/issues/102/comments","events_url":"https://api.github.com/repos/motion-kit/motion-kit/issues/102/events","html_url":"https://github.com/motion-kit/motion-kit/issues/102","id":56179603,"number":102,"title":"Question: How to constrain UIScrollView so that it does not move vertically?","user":{"login":"matthewsinclair","id":311495,"avatar_url":"https://avatars.githubusercontent.com/u/311495?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewsinclair","html_url":"https://github.com/matthewsinclair","followers_url":"https://api.github.com/users/matthewsinclair/followers","following_url":"https://api.github.com/users/matthewsinclair/following{/other_user}","gists_url":"https://api.github.com/users/matthewsinclair/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewsinclair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewsinclair/subscriptions","organizations_url":"https://api.github.com/users/matthewsinclair/orgs","repos_url":"https://api.github.com/users/matthewsinclair/repos","events_url":"https://api.github.com/users/matthewsinclair/events{/privacy}","received_events_url":"https://api.github.com/users/matthewsinclair/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-01T21:43:41Z","updated_at":"2015-02-02T02:23:43Z","closed_at":null,"body":"I have a reasonably complex layout that I am working with that contains a simple `UIView` which contains a `UIScrollView`, a `UIPageControl` and a number of `UIWebViews`. The intent of the control is to be a re-usable component that I can place in a variety of spots, but in particular, I want to be able to put it inside a `UITableViewCell`. This will allow to me to have a cell that has a number of web views that can be scrolled side to side (inside the cell).\r\n\r\nI have the control working, with one exception. I can't seem to constrain the `UIScrollView` so that is doesn't move up and down. At this stage, I have some demo code that just situates the control (called `Tillless::Shp::ProductCategoryLeadView`) into a standard `PM::Screen`. \r\n\r\nHere's the output of `tree` from the RubyMotion repl:\r\n```\r\n(main)> tree                         \r\n  0: . UIWindow(#10fbed470, [[0.0, 0.0], [320.0, 568.0]])\r\n  1: `-- UILayoutContainerView(#11842e120, [[0.0, 0.0], [320.0, 568.0]])\r\n  2:     +-- UITransitionView(#118313c50, [[0.0, 0.0], [320.0, 568.0]])\r\n  3:     |   `-- UIViewControllerWrapperView(#1112c8520, [[0.0, 0.0], [320.0, 568.0]])\r\n  4:     |       `-- UILayoutContainerView(#11841f6a0, [[0.0, 0.0], [320.0, 568.0]])\r\n  5:     |           +-- UINavigationTransitionView(#1184013a0, [[0.0, 0.0], [320.0, 568.0]])\r\n  6:     |           |   `-- UIViewControllerWrapperView(#118442c10, [[0.0, 0.0], [320.0, 568.0]])\r\n  7:     |           |       `-- UIView(#1112dc240, [[0.0, 64.0], [320.0, 504.0]])\r\n  8:     |           |           `-- Tillless::Shp::ProductCategoryLeadView(#1112dc6d0, [[0.0, 0.0], [320.0, 504.0]])\r\n  9:     |           |               +-- UIScrollView(#1112e1c20, [[0.0, 0.0], [320.0, 504.0]])\r\n 10:     |           |               |   +-- Tillless::Shp::ProductCategoryLeadWebCell(#1185e3e80, [[0.0, 0.0], [320.0, 504.0]])\r\n 11:     |           |               |   |   `-- UIWebView(#1185e4b90, [[0.0, 0.0], [320.0, 504.0]])\r\n 12:     |           |               |   |       `-- _UIWebViewScrollView(#1185e8a40, [[0.0, 0.0], [320.0, 504.0]])\r\n 13:     |           |               |   |           +-- UIWebBrowserView(#114152200, [[0.0, 0.0], [320.0, 504.0]])\r\n 14:     |           |               |   |           +-- UIImageView(#1184a7060, [[317.5, -36.0], [2.5, 36.0]])\r\n 15:     |           |               |   |           `-- UIImageView(#118a42d70, [[-36.0, 501.5], [36.0, 2.5]])\r\n 16:     |           |               |   +-- Tillless::Shp::ProductCategoryLeadWebCell(#11844aab0, [[320.0, 0.0], [320.0, 504.0]])\r\n 17:     |           |               |   |   `-- UIWebView(#118480630, [[0.0, 0.0], [320.0, 504.0]])\r\n 18:     |           |               |   |       `-- _UIWebViewScrollView(#1183defc0, [[0.0, 0.0], [320.0, 504.0]])\r\n 19:     |           |               |   |           +-- UIWebBrowserView(#114904a00, [[0.0, 0.0], [320.0, 504.0]])\r\n 20:     |           |               |   |           +-- UIImageView(#118304de0, [[317.5, -36.0], [2.5, 36.0]])\r\n 21:     |           |               |   |           `-- UIImageView(#1183b1de0, [[-36.0, 501.5], [36.0, 2.5]])\r\n 22:     |           |               |   `-- Tillless::Shp::ProductCategoryLeadWebCell(#11832ebe0, [[640.0, 0.0], [320.0, 504.0]])\r\n 23:     |           |               |       `-- UIWebView(#118355720, [[0.0, 0.0], [320.0, 504.0]])\r\n 24:     |           |               |           `-- _UIWebViewScrollView(#11b08ad00, [[0.0, 0.0], [320.0, 504.0]])\r\n 25:     |           |               |               +-- UIWebBrowserView(#11016fa00, [[0.0, 0.0], [320.0, 504.0]])\r\n 26:     |           |               |               +-- UIImageView(#11b096d70, [[317.5, -36.0], [2.5, 36.0]])\r\n 27:     |           |               |               `-- UIImageView(#11b094c40, [[-36.0, 501.5], [36.0, 2.5]])\r\n 28:     |           |               `-- UIPageControl(#1112de320, [[0.0, 0.0], [320.0, 30.0]])\r\n 29:     |           |                   +-- UIView(#11b088fe0, [[140.5, 11.5], [7.0, 7.0]])\r\n 30:     |           |                   +-- UIView(#1185b40f0, [[156.5, 11.5], [7.0, 7.0]])\r\n 31:     |           |                   `-- UIView(#1185c46c0, [[172.5, 11.5], [7.0, 7.0]])\r\n 32:     |           +-- UINavigationBar(#11841f7a0, [[0.0, 20.0], [320.0, 44.0]])\r\n 33:     |           |   +-- _UINavigationBarBackground(#11841f950, [[0.0, -20.0], [320.0, 64.0]])\r\n 34:     |           |   |   `-- UIImageView(#11841fae0, [[0.0, 64.0], [320.0, 0.5]])\r\n 35:     |           |   +-- UINavigationItemView(#1112d0c70, [[110.0, 8.0], [100.0, 27.0]])\r\n 36:     |           |   |   `-- UILabel(#1112d41e0, [[0.0, 4.0], [100.0, 20.0]], text: \"Category 0-1\")\r\n 37:     |           |   +-- UINavigationItemButtonView(#1185d0300, [[8.0, 6.0], [54.0, 30.0]])\r\n 38:     |           |   |   `-- UILabel(#1185d0880, [[19.0, -52.5], [35.0, 18.0]], text: \"Shop\")\r\n 39:     |           |   `-- _UINavigationBarBackIndicatorView(#1184208a0, [[8.0, 11.5], [13.0, 21.0]])\r\n 40:     |           `-- UIToolbar(#118865830, [[0.0, 568.0], [320.0, 44.0]])\r\n 41:     |               +-- _UIToolbarBackground(#1112e2260, [[0.0, 0.0], [320.0, 44.0]])\r\n 42:     |               |   `-- _UIBackdropView(#1112e3630, [[0.0, 0.0], [320.0, 44.0]])\r\n 43:     |               |       +-- _UIBackdropEffectView(#1112e3c60, [[0.0, 0.0], [320.0, 44.0]])\r\n 44:     |               |       `-- UIView(#1112e3d60, [[0.0, 0.0], [320.0, 44.0]])\r\n 45:     |               `-- UIImageView(#1112e7c20, [[0.0, -0.5], [320.0, 0.5]])\r\n 46:     `-- UITabBar(#11842e260, [[0.0, 519.0], [320.0, 49.0]])\r\n 47:         +-- _UITabBarBackgroundView(#1183eeb50, [[0.0, 0.0], [320.0, 49.0]])\r\n 48:         |   `-- _UIBackdropView(#1183efed0, [[0.0, 0.0], [320.0, 49.0]])\r\n 49:         |       +-- _UIBackdropEffectView(#1183f0430, [[0.0, 0.0], [320.0, 49.0]])\r\n 50:         |       `-- UIView(#1183f0510, [[0.0, 0.0], [320.0, 49.0]])\r\n 51:         +-- UITabBarButton(#11832f6f0, [[2.0, 1.0], [60.0, 48.0]])\r\n 52:         |   +-- UITabBarSwappableImageView(#118331eb0, [[17.0, 5.5], [25.0, 25.0]])\r\n 53:         |   `-- UITabBarButtonLabel(#11832fc70, [[9.0, 35.0], [41.5, 12.0]], text: \"Featured\")\r\n 54:         +-- UITabBarButton(#118339090, [[66.0, 1.0], [60.0, 48.0]])\r\n 55:         |   +-- UITabBarSwappableImageView(#11833a390, [[17.5, 5.5], [25.0, 25.0]])\r\n 56:         |   `-- UITabBarButtonLabel(#118339250, [[17.5, 35.0], [25.0, 12.0]], text: \"Shop\")\r\n 57:         +-- UITabBarButton(#11833eea0, [[130.0, 1.0], [60.0, 48.0]])\r\n 58:         |   +-- UITabBarSwappableImageView(#1183400a0, [[17.5, 5.5], [25.0, 25.0]])\r\n 59:         |   `-- UITabBarButtonLabel(#11833f060, [[20.5, 35.0], [19.0, 12.0]], text: \"Bag\")\r\n 60:         +-- UITabBarButton(#118343fc0, [[194.0, 1.0], [60.0, 48.0]])\r\n 61:         |   +-- UITabBarSwappableImageView(#1183451c0, [[17.0, 5.5], [25.0, 25.0]])\r\n 62:         |   `-- UITabBarButtonLabel(#118344180, [[14.5, 35.0], [30.5, 12.0]], text: \"Stores\")\r\n 63:         +-- UITabBarButton(#118348190, [[258.0, 1.0], [60.0, 48.0]])\r\n 64:         |   +-- UITabBarSwappableImageView(#118349390, [[17.5, 5.5], [25.0, 25.0]])\r\n 65:         |   `-- UITabBarButtonLabel(#118348350, [[10.5, 35.0], [39.0, 12.0]], text: \"Account\")\r\n 66:         `-- UIImageView(#1183f3790, [[0.0, -0.5], [320.0, 0.5]])\r\n\r\n=> UIWindow(#10fbed470, [[0.0, 0.0], [320.0, 568.0]])\r\n```\r\n\r\nHere's an example of the screen when it is running in the sim. The first screen-shot shows the first image (of three) positioned so that the bottom of the image is against the bottom of the sim window (under the toolbar), and the top of the image is level with the bottom of the nav bar. This is the desired positioning.\r\n\r\n![screen shot 2015-02-02 at 8 24 30 am](https://cloud.githubusercontent.com/assets/311495/5993949/561cdcd2-aab6-11e4-978a-5abcf769dcbd.png)\r\n\r\nHowever, in the second screen shot, you can see that the image has been scrolled up by 49 pixels so that it slides underneath the nav bar. This is what I want to try to stop. In fact, I don't want any up/down scrolling of the views in the `UIScrollView` at all, if I can avoid it. \r\n\r\n![screen shot 2015-02-02 at 8 24 36 am](https://cloud.githubusercontent.com/assets/311495/5993950/5a96d088-aab6-11e4-8356-6af60bea5d6b.png)\r\n\r\nI've been able to size everything else properly, and I even managed to get the `UIWebView` pages sized properly using MotionKit constraints within the `UIScrollView` (although that did take me hours to get right because the frame that contains the `UIScrollView` is not resolved at the point when the sub-views are added to the `UIScrollView`, which means I have to come back later (during `layoutSubviews`) and do a one-off re-calculation of the `UIScrollView`'s `contentSize` value, and accordingly position the sub-pages in the fully extended `UIScrollView`. But that's a whole other story ...\r\n\r\nIt feels like what I want to do (have the `UIScrollView` prevent up/down scrolling) should be easy, and in fact, there are a number of posts around the web (eg [here](http://stackoverflow.com/questions/1062693/how-to-disable-horizontal-scrolling-of-scrollview-iphone) and [here](http://stackoverflow.com/questions/5271521/how-to-lock-the-horizontal-scrolling-of-a-scrollview-in-ios)), but they all seem horribly hacky.\r\n\r\nAfter spending hours on this last night, I've given up. \r\n\r\nAny ideas on how this might be accomplished?"},"comment":{"url":"https://api.github.com/repos/motion-kit/motion-kit/issues/comments/72398767","html_url":"https://github.com/motion-kit/motion-kit/issues/102#issuecomment-72398767","issue_url":"https://api.github.com/repos/motion-kit/motion-kit/issues/102","id":72398767,"user":{"login":"matthewsinclair","id":311495,"avatar_url":"https://avatars.githubusercontent.com/u/311495?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewsinclair","html_url":"https://github.com/matthewsinclair","followers_url":"https://api.github.com/users/matthewsinclair/followers","following_url":"https://api.github.com/users/matthewsinclair/following{/other_user}","gists_url":"https://api.github.com/users/matthewsinclair/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewsinclair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewsinclair/subscriptions","organizations_url":"https://api.github.com/users/matthewsinclair/orgs","repos_url":"https://api.github.com/users/matthewsinclair/repos","events_url":"https://api.github.com/users/matthewsinclair/events{/privacy}","received_events_url":"https://api.github.com/users/matthewsinclair/received_events","type":"User","site_admin":false},"created_at":"2015-02-02T02:23:43Z","updated_at":"2015-02-02T02:23:43Z","body":"Here's the content of the layout that controls each of the `UIWebView` instances:\r\n```\r\nmodule Tillless\r\n  module Shp\r\n    class ProductCategoryLeadWebCellLayout < MK::Layout\r\n      def layout\r\n        # root :cell do\r\n          @web_view = add UIWebView, :web_view\r\n          @web_view.setUserInteractionEnabled false\r\n        # end\r\n      end\r\n\r\n      def web_view_style\r\n        scrollView.scrollEnabled = false\r\n        scrollView.bounces = false\r\n        scrollView.alwaysBounceVertical = false\r\n        constraints do\r\n          x.equals(0)\r\n          y.equals(0)\r\n          width.equals(:superview)\r\n          height.equals(:superview)\r\n        end\r\n      end\r\n    end\r\n\r\n  end\r\nend\r\n```"}}