From f1e46f452b8825859398c11788aafe7f469e846e Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 8 Aug 2012 17:33:11 +0200 Subject: ios: use viewWillLayoutSubviews instead of layout out only after rotation. Handle the case where if the device is rotated while showing the outline view, popping back to the document view would show the pages using the old rotation layout. --- ios/main.m | 65 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'ios') diff --git a/ios/main.m b/ios/main.m index 6f2c3b9c..70cd3712 100644 --- a/ios/main.m +++ b/ios/main.m @@ -1053,16 +1053,23 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, - (void) viewWillAppear: (BOOL)animated { - CGSize size = [canvas frame].size; - width = size.width; - height = size.height; - [self setTitle: [key lastPathComponent]]; [slider setValue: current]; [indicator setText: [NSString stringWithFormat: @" %d of %d ", current+1, count_pages(doc)]]; + [[self navigationController] setToolbarHidden: NO animated: animated]; +} + +- (void) viewWillLayoutSubviews +{ + CGSize size = [canvas frame].size; + int max_width = MAX(width, size.width); + + width = size.width; + height = size.height; + [canvas setContentInset: UIEdgeInsetsZero]; [canvas setContentSize: CGSizeMake(count_pages(doc) * width, height)]; [canvas setContentOffset: CGPointMake(current * width, 0)]; @@ -1070,7 +1077,24 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, [sliderWrapper setWidth: SLIDER_W]; [searchBar setFrame: CGRectMake(0,0,SEARCH_W,32)]; - [[self navigationController] setToolbarHidden: NO animated: animated]; + [[[self navigationController] toolbar] setNeedsLayout]; // force layout! + + // use max_width so we don't clamp the content offset too early during animation + [canvas setContentSize: CGSizeMake(count_pages(doc) * max_width, height)]; + [canvas setContentOffset: CGPointMake(current * width, 0)]; + + for (MuPageView *view in [canvas subviews]) { + if ([view number] == current) { + [view setFrame: CGRectMake([view number] * width, 0, width-GAP, height)]; + [view willRotate]; + } + } + for (MuPageView *view in [canvas subviews]) { + if ([view number] != current) { + [view setFrame: CGRectMake([view number] * width, 0, width-GAP, height)]; + [view willRotate]; + } + } } - (void) viewDidAppear: (BOOL)animated @@ -1401,37 +1425,6 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, return YES; } -- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration -{ - CGSize size = [canvas frame].size; - int max_width = MAX(width, size.width); - - width = size.width; - height = size.height; - - [sliderWrapper setWidth: SLIDER_W]; - [searchBar setFrame: CGRectMake(0,0,SEARCH_W,32)]; - - [[[self navigationController] toolbar] setNeedsLayout]; // force layout! - - // use max_width so we don't clamp the content offset too early during animation - [canvas setContentSize: CGSizeMake(count_pages(doc) * max_width, height)]; - [canvas setContentOffset: CGPointMake(current * width, 0)]; - - for (MuPageView *view in [canvas subviews]) { - if ([view number] == current) { - [view setFrame: CGRectMake([view number] * width, 0, width-GAP, height)]; - [view willRotate]; - } - } - for (MuPageView *view in [canvas subviews]) { - if ([view number] != current) { - [view setFrame: CGRectMake([view number] * width, 0, width-GAP, height)]; - [view willRotate]; - } - } -} - - (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation)o { [canvas setContentSize: CGSizeMake(count_pages(doc) * width, height)]; -- cgit v1.2.3