|
15 | 15 | #import "ASRangeController.h" |
16 | 16 | #import "ASDisplayNodeInternal.h" |
17 | 17 | #import "ASBatchFetching.h" |
| 18 | +#import "ASInternalHelpers.h" |
18 | 19 |
|
19 | 20 | //#define LOG(...) NSLog(__VA_ARGS__) |
20 | 21 | #define LOG(...) |
@@ -131,6 +132,8 @@ @interface ASTableView () <ASRangeControllerDelegate, ASDataControllerSource> { |
131 | 132 |
|
132 | 133 | NSIndexPath *_contentOffsetAdjustmentTopVisibleRow; |
133 | 134 | CGFloat _contentOffsetAdjustment; |
| 135 | + |
| 136 | + BOOL _pendingRelayoutForAllRows; |
134 | 137 | } |
135 | 138 |
|
136 | 139 | @property (atomic, assign) BOOL asyncDataSourceLocked; |
@@ -183,6 +186,11 @@ - (void)configureWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled |
183 | 186 | _batchContext = [[ASBatchContext alloc] init]; |
184 | 187 |
|
185 | 188 | _automaticallyAdjustsContentOffset = NO; |
| 189 | + |
| 190 | + if (ASSystemVersionLessThan8()) { |
| 191 | + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
| 192 | + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil]; |
| 193 | + } |
186 | 194 | } |
187 | 195 |
|
188 | 196 | - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style |
@@ -220,6 +228,11 @@ - (void)dealloc |
220 | 228 | // This bug might be iOS 7-specific. |
221 | 229 | super.delegate = nil; |
222 | 230 | super.dataSource = nil; |
| 231 | + |
| 232 | + if (ASSystemVersionLessThan8()) { |
| 233 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 234 | + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; |
| 235 | + } |
223 | 236 | } |
224 | 237 |
|
225 | 238 | #pragma mark - |
@@ -343,6 +356,31 @@ - (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL completed))c |
343 | 356 | [_dataController endUpdatesAnimated:animated completion:completion]; |
344 | 357 | } |
345 | 358 |
|
| 359 | +#pragma mark - |
| 360 | +#pragma mark Orientation Change Handling |
| 361 | + |
| 362 | +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection |
| 363 | +{ |
| 364 | + _pendingRelayoutForAllRows = YES; |
| 365 | +} |
| 366 | + |
| 367 | +- (void)deviceOrientationDidChange |
| 368 | +{ |
| 369 | + _pendingRelayoutForAllRows = YES; |
| 370 | +} |
| 371 | + |
| 372 | +- (void)layoutSubviews |
| 373 | +{ |
| 374 | + [super layoutSubviews]; |
| 375 | + |
| 376 | + if (_pendingRelayoutForAllRows) { |
| 377 | + _pendingRelayoutForAllRows = NO; |
| 378 | + [self beginUpdates]; |
| 379 | + [_dataController relayoutAllRows]; |
| 380 | + [self endUpdates]; |
| 381 | + } |
| 382 | +} |
| 383 | + |
346 | 384 | #pragma mark - |
347 | 385 | #pragma mark Editing |
348 | 386 |
|
|
0 commit comments