title: UIScrollView with horizontal paging` does not center subview
body: <p>I am trying to use UIScrollView with paging enabled. I am adding various UIView to UISCrollView as a subviews. I want those subview to be smaller than size of scroll view so I have modified my constrains accordingly. Now when I actually swipe them left/ right then do not happened to be in center. I was expecting it to show previous / next view peeking from sides with current page in center. </p>
  
  <p>This is what it looks like
  <a href="https://i.stack.imgur.com/M8dzQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M8dzQ.png" alt="enter image description here"></a></p>
  
  <p>Below is my code scrollview implementation</p>
  
  <pre><code>    //
      //  ViewController.m
      //  Paging
      //
  
  #import "ViewController.h"
  
  @interface ViewController ()
  @property (nonatomic, strong) UIScrollView *pagingScrollView;
  @end
  
  @implementation ViewController
  - (UIScrollView *)pagingScrollView {
      if (!_pagingScrollView) {
          _pagingScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
          _pagingScrollView.translatesAutoresizingMaskIntoConstraints = NO;
          _pagingScrollView.backgroundColor = [UIColor orangeColor];
          _pagingScrollView.showsHorizontalScrollIndicator = NO;
          _pagingScrollView.showsVerticalScrollIndicator = NO;
          _pagingScrollView.contentInset = UIEdgeInsetsZero;
          _pagingScrollView.pagingEnabled = YES;
          _pagingScrollView.clipsToBounds = NO;
          _pagingScrollView.bounces = NO;
      }
      return _pagingScrollView;
  }
  - (void)viewDidLoad {
      [super viewDidLoad];
      [self scrollViewSetUp];
  
      NSDictionary *views = NSDictionaryOfVariableBindings(_pagingScrollView);
  
      [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_pagingScrollView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:views]];
  
      [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_pagingScrollView]|"
                                                                        options:0
                                                                        metrics:nil
                                                                          views:views]];
  }
  
  - (void)scrollViewSetUp {
  
      [self.view addSubview:self.pagingScrollView];
  
      UIView *lastView = nil;
      NSInteger arrayCount = 5;
  
      for(NSInteger index = 0; index &lt; arrayCount; index++)
      {
          UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
          view.translatesAutoresizingMaskIntoConstraints = NO;
          view.backgroundColor = [UIColor yellowColor];
  
          [self.pagingScrollView addSubview:view];
  
          [self.pagingScrollView addConstraint:[NSLayoutConstraint constraintWithItem:view
                                                                          attribute:NSLayoutAttributeTop
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:self.pagingScrollView
                                                                          attribute:NSLayoutAttributeTop
                                                                         multiplier:1
                                                                           constant:40]];
  
          [self.pagingScrollView addConstraint:[NSLayoutConstraint constraintWithItem:view
                                                                          attribute:NSLayoutAttributeHeight
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:self.pagingScrollView
                                                                          attribute:NSLayoutAttributeHeight
                                                                         multiplier:0.80
                                                                           constant:0]];
  
          [self.pagingScrollView addConstraint:[NSLayoutConstraint constraintWithItem:view
                                                                          attribute:NSLayoutAttributeWidth
                                                                          relatedBy:NSLayoutRelationEqual
                                                                             toItem:self.pagingScrollView
                                                                          attribute:NSLayoutAttributeWidth
                                                                         multiplier:0.80
                                                                           constant:0]];
  
          if (lastView == nil &amp;&amp; index == 0){
              [self.pagingScrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[view(==_pagingScrollView)]"
                                                                                          options:0
                                                                                          metrics:nil
                                                                                            views:@{@"view":view, @"_pagingScrollView":_pagingScrollView}]];
          } else {
              [self.pagingScrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[lastView]-20-[view]"
                                                                                          options:0
                                                                                          metrics:nil
                                                                                            views:@{@"lastView":lastView, @"view":view, @"_pagingScrollView":_pagingScrollView}]];
          }
  
          if(index == arrayCount-1) {
              [self.pagingScrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view]-20-|"
                                                                                          options:0
                                                                                          metrics:nil
                                                                                            views:@{@"view":view}]];
          }
  
          lastView = view;
      }
  }
  @end
  </code></pre>
  
  <p>Any pointers/comments/feedback highly appreciated. Thanks.</p>