I use iOS 6, UIScrollView swap, and a clean machine.
Summary: I created a view controller that scrolls content pages. Some of the views are created and customized in the storyboard, others in software. Here's the hierarchy of views:
- Main view (storyboard) - UIScrollView (storyboard) - content view (programmatically) - subviews representing pages of content (programmatically)
Limitations for the scroll view are configured in IB. Here's how I set up restrictions for representing content in code:
- (void)viewDidLoad { // ABPageScrollerContentView is a subclass of UIView; it overrides intrinsicContentSize; the size is calculated without referencing the scroll view dimensions self.contentView = [[ABPageScrollerContentView alloc] init]; self.contentView.translatesAutoresizingMaskIntoConstraints = NO; [self.pageScrollerView addSubview:self.contentView]; // configure constraints between scroll view and content view... UIView *contentView = self.contentView; NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(contentView); [self.pageScrollerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:0 views:viewsDictionary]]; [self.pageScrollerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|" options:0 metrics:0 views:viewsDictionary]]; // the content view subviews are added/removed in the tilePages method (not shown); tilePages is called later in the view controller lifecycle... }
If the user clicks the edit button, another view controller is presented using segue in the storyboard. After the view controller is rejected, the system seems to inexplicably modify the presentation frame of the content, even if the restrictions are not changed.
I rejected the presented view controller in the following delegate method:
- (void)didExitEditPageViewVC:(id)controller {
I do not understand how the x-component of the beginning of the frame has changed from 0 to -170. The restrictions are identical before and after the view controller rejects.
Here is the frame and limitations right before the rejectViewControllerAnimated method is called: completion ::
(lldb) po self.contentView $0 = 0x1ede2b40 <AEBPageScrollerContentView: 0x1ede2b40; frame = (0 0; 1020 460); layer = <CALayer: 0x1edd6f00>> (lldb) po self.pageScrollerView.constraints $1 = 0x1ed076c0 <__NSArrayM 0x1ed076c0>( <NSLayoutConstraint:0x1ede2980 H:|-(0)-[AEBPageScrollerContentView:0x1ede2b40] (Names: '|':UIScrollView:0x1edd3410 )>, <NSLayoutConstraint:0x1eded480 H:[AEBPageScrollerContentView:0x1ede2b40]-(0)-| (Names: '|':UIScrollView:0x1edd3410 )>, <NSLayoutConstraint:0x1edecbc0 V:|-(0)-[AEBPageScrollerContentView:0x1ede2b40] (Names: '|':UIScrollView:0x1edd3410 )>, <NSLayoutConstraint:0x1ede1040 V:[AEBPageScrollerContentView:0x1ede2b40]-(0)-| (Names: '|':UIScrollView:0x1edd3410 )> )
Here is the frame and limitations after displaying the view controller:
contentView = <AEBPageScrollerContentView: 0x1ede2b40; frame = (-170 0; 1020 460); layer = <CALayer: 0x1edd6f00>> self.pageScrollerView.constraints = ( "<NSLayoutConstraint:0x1ede2980 H:|-(0)-[AEBPageScrollerContentView:0x1ede2b40] (Names: '|':UIScrollView:0x1edd3410 )>", "<NSLayoutConstraint:0x1eded480 H:[AEBPageScrollerContentView:0x1ede2b40]-(0)-| (Names: '|':UIScrollView:0x1edd3410 )>", "<NSLayoutConstraint:0x1edecbc0 V:|-(0)-[AEBPageScrollerContentView:0x1ede2b40] (Names: '|':UIScrollView:0x1edd3410 )>", "<NSLayoutConstraint:0x1ede1040 V:[AEBPageScrollerContentView:0x1ede2b40]-(0)-| (Names: '|':UIScrollView:0x1edd3410 )>" )
Why did the presentation frame change unexpectedly? And why does this not correspond to what is dictated by restrictions?
A pending call to hasAmbiguousLayout unexpectedly returns false. No exceptions are thrown. Scrolling even scrolls through scrolls, although the content view is partially off-screen.
No, where do I explicitly set the size of the scroll content; I leave this in the system. The content view has its own size (the size of the content view looks accurate, and the problem with the content presentation is a problem).
Resetting scroll content matches before and after rejecting the view controller. However, the offset of the x-component of the start of the content presentation is proportional to the content offset. The larger the content offset, the more negative the x component of the start of the content presentation after the modal presentation controller is rejected. And when the content is offset, the βzeroβ x component is zero. Therefore, if the modal presentation controller is presented when viewing the first page of the content (when the content offset is βzeroβ), the content presentation frame is correct when the view controller is fired. The only circumstance in which the content presentation frame correctly reflects its limitations is the case when the content offset is zero.
I tried inserting calls into layoutIfNeeded in different places without any results.
Any suggestions?