Skip to content

Commit

Permalink
Prevent unnecessary setting on contentOffset in DemoViewController, f…
Browse files Browse the repository at this point in the history
…ixes Cocoanetics#809

On iOS 8 viewDidLayoutSubviews is called and that would set the contentOffset which we are doing because of the custom layout. A proper fix would be to change the whole demo to story board and no longer manually set the insets of all the scroll views.
  • Loading branch information
odrobnik committed Oct 17, 2014
1 parent 8258697 commit 666b71a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 62 deletions.
17 changes: 16 additions & 1 deletion Demo/Resources/CurrentTest.html
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<oliver style="width:40; height:40;display:none;"><p><strong>BOX1</strong></p></oliver><oliver style="width:40; height:40;display:block;"><p><strong>BOX2</strong></p></oliver><p>END</p>
<img src="http://e.hiphotos.baidu.com/image/pic/item/9358d109b3de9c824d8dc53c6e81800a18d8439c.jpg" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<img src="http://h.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf51f4f633b68e5494eef01f7aa5.jpg" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<img src="http://h.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf51f4f633b68e5494eef01f7aa5.jpg" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<img src="http://h.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf51f4f633b68e5494eef01f7aa5.jpg" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
75 changes: 16 additions & 59 deletions Demo/Source/DemoAboutViewController.xib
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1552</int>
<string key="IBDocument.SystemVersion">12C3006</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<int key="IBDocument.SystemTarget">2048</int>
<string key="IBDocument.SystemVersion">14A388a</string>
<string key="IBDocument.InterfaceBuilderVersion">6245</string>
<string key="IBDocument.AppKitVersion">1343.14</string>
<string key="IBDocument.HIToolboxVersion">755.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">2083</string>
<string key="NS.object.0">6238</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
Expand All @@ -31,15 +31,14 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<nil key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIView" id="396884822">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 548}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
Expand All @@ -52,8 +51,6 @@
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 548}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="396884822"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
Expand All @@ -63,6 +60,8 @@
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUIScreenMetrics" key="IBUISimulatedDestinationMetrics">
<string key="IBUISimulatedSizeMetricsClass">IBUIScreenMetrics</string>
<string key="IBUITargetRuntime">IBCocoaTouchFramework</string>
<string key="IBUIDisplayName">iPhone 4-inch</string>
<object class="NSMutableDictionary" key="IBUINormalizedOrientationToSizeMap">
<bool key="EncodedWithXMLCoder">YES</bool>
<array key="dict.sortedKeys">
Expand All @@ -74,15 +73,13 @@
<string>{568, 320}</string>
</array>
</object>
<string key="IBUITargetRuntime">IBCocoaTouchFramework</string>
<string key="IBUIDisplayName">Retina 4 Full Screen</string>
<int key="IBUIType">2</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
<array key="connectionRecords">
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
Expand Down Expand Up @@ -149,55 +146,15 @@
<nil key="sourceID"/>
<int key="maxID">9</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">DTAttributedTextView</string>
<string key="superclassName">UIScrollView</string>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="backgroundView">UIView</string>
<string key="textDelegate">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="backgroundView">
<string key="name">backgroundView</string>
<string key="candidateClassName">UIView</string>
</object>
<object class="IBToOneOutletInfo" key="textDelegate">
<string key="name">textDelegate</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/DTAttributedTextView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">DemoAboutViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">attributedTextView</string>
<string key="NS.object.0">DTAttributedTextView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">attributedTextView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">attributedTextView</string>
<string key="candidateClassName">DTAttributedTextView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/DemoAboutViewController.h</string>
</object>
</object>
</array>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">NO</bool>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<integer value="4600" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">2083</string>
</data>
</archive>
24 changes: 22 additions & 2 deletions Demo/Source/DemoTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ @implementation DemoTextViewController
// private
NSURL *lastActionLink;
NSMutableSet *mediaPlayers;

BOOL _needsAdjustInsetsOnLayout;
}


Expand All @@ -70,7 +72,10 @@ - (id)init
self.navigationItem.titleView = _segmentedControl;

[self _updateToolbarForMode];


_needsAdjustInsetsOnLayout = YES;

self.automaticallyAdjustsScrollViewInsets = YES;
}
return self;
}
Expand Down Expand Up @@ -257,12 +262,23 @@ - (void)viewWillDisappear:(BOOL)animated;
[super viewWillDisappear:animated];
}

- (BOOL)prefersStatusBarHidden
{
// prevent hiding of status bar in landscape because this messes up the layout guide calc
return NO;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
_needsAdjustInsetsOnLayout = YES;
}

// this is only called on >= iOS 5
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

if (![self respondsToSelector:@selector(topLayoutGuide)])
if (![self respondsToSelector:@selector(topLayoutGuide)] || !_needsAdjustInsetsOnLayout)
{
return;
}
Expand All @@ -271,6 +287,8 @@ - (void)viewDidLayoutSubviews
CGFloat topInset = [[self valueForKeyPath:@"topLayoutGuide.length"] floatValue];
CGFloat bottomInset = [[self valueForKeyPath:@"bottomLayoutGuide.length"] floatValue];

NSLog(@"%f top", topInset);

UIEdgeInsets outerInsets = UIEdgeInsetsMake(topInset, 0, bottomInset, 0);
UIEdgeInsets innerInsets = outerInsets;
innerInsets.left += 10;
Expand Down Expand Up @@ -300,6 +318,8 @@ - (void)viewDidLayoutSubviews
_htmlView.contentInset = outerInsets;
_htmlView.contentOffset = outerScrollOffset;
_htmlView.scrollIndicatorInsets = outerInsets;

_needsAdjustInsetsOnLayout = NO;
}

#pragma mark Private Methods
Expand Down

0 comments on commit 666b71a

Please sign in to comment.