Skip to content

Commit

Permalink
[BUGFIX] Fix #286.
Browse files Browse the repository at this point in the history
Layout stragety adjust.
[BEFORE] Return if height not changed.
[NOW] Layout everytime when viewDidLayoutSubviews called.

Signed-off-by: wangmchn <wangmchn@163.com>
  • Loading branch information
wangmchn committed Jul 15, 2017
1 parent 6c6d342 commit 1503214
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions WMPageController/WMPageController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
static NSInteger const kWMUndefinedIndex = -1;
static NSInteger const kWMControllerCountUndefined = -1;
@interface WMPageController () {
CGFloat _targetX, _superviewHeight;
CGFloat _targetX;
CGRect _contentViewFrame, _menuViewFrame;
BOOL _hasInited, _shouldNotScroll, _isTabBarHidden;
BOOL _hasInited, _shouldNotScroll;
NSInteger _initializedIndex, _controllerCount, _markedSelectIndex;
}
@property (nonatomic, strong, readwrite) UIViewController *currentViewController;
Expand Down Expand Up @@ -85,19 +85,13 @@ - (instancetype)init {
return self;
}

- (void)setEdgesForExtendedLayout:(UIRectEdge)edgesForExtendedLayout {
if (self.edgesForExtendedLayout == edgesForExtendedLayout) return;
[super setEdgesForExtendedLayout:edgesForExtendedLayout];

if (_hasInited) {
_hasInited = NO;
[self viewDidLayoutSubviews];
}
}

- (void)forceLayoutSubviews {
_hasInited = NO;
[self viewDidLayoutSubviews];
if (!self.childControllersCount) return;
// 计算宽高及子控制器的视图frame
[self wm_calculateSize];
[self wm_adjustScrollViewFrame];
[self wm_adjustMenuViewFrame];
[self wm_adjustDisplayingViewControllersFrame];
}

- (void)setScrollEnable:(BOOL)scrollEnable {
Expand Down Expand Up @@ -696,21 +690,8 @@ - (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];

if (!self.childControllersCount) return;

CGFloat oldSuperviewHeight = _superviewHeight;
_superviewHeight = self.view.frame.size.height;
BOOL oldTabBarIsHidden = _isTabBarHidden;
_isTabBarHidden = [self wm_bottomView].hidden;

BOOL shouldNotLayout = (_hasInited && _superviewHeight == oldSuperviewHeight && _isTabBarHidden == oldTabBarIsHidden);
if (shouldNotLayout) return;
// 计算宽高及子控制器的视图frame
[self wm_calculateSize];
[self wm_adjustScrollViewFrame];
[self wm_adjustMenuViewFrame];
[self wm_adjustDisplayingViewControllersFrame];
[self forceLayoutSubviews];
_hasInited = YES;
[self.view layoutIfNeeded];
[self wm_delaySelectIndexIfNeeded];
}

Expand Down

0 comments on commit 1503214

Please sign in to comment.