summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorMatt Holgate <matt@emobix.co.uk>2014-07-16 18:33:25 +0100
committerMatt Holgate <matt@emobix.co.uk>2014-07-16 18:33:25 +0100
commit5c85915b5829d16129ee00f3eaba8ad0af2be552 (patch)
treea610f83fab477fb3a911e7b84378e40ff8eac858 /platform/ios
parent6483930539da2a48c37da7b508f05d71fc2c2d56 (diff)
downloadmupdf-5c85915b5829d16129ee00f3eaba8ad0af2be552.tar.xz
Fix page changing when rotating the device.
A bug in UIKit means our 'scrollViewDidScroll' method is called during screen rotation. This ended up corrupting our current page number because the width of the screen had changed at this point, but the pages hadn't yet been resized/repositioned (I assume). The workaround is to ignore calls to scrollViewDidScroll during rotation.
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/Classes/MuDocumentController.m23
1 files changed, 23 insertions, 0 deletions
diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m
index 36f2c867..35982ba7 100644
--- a/platform/ios/Classes/MuDocumentController.m
+++ b/platform/ios/Classes/MuDocumentController.m
@@ -123,6 +123,9 @@ static void saveDoc(char *current_path, fz_document *doc)
}
@implementation MuDocumentController
+{
+ BOOL _isRotating;
+}
- (id) initWithFilename: (NSString*)filename path:(char *)cstr document: (MuDocRef *)aDoc
{
@@ -974,6 +977,16 @@ static void saveDoc(char *current_path, fz_document *doc)
- (void) scrollViewDidScroll: (UIScrollView*)scrollview
{
+ // scrollViewDidScroll seems to get called part way through a screen rotation.
+ // (This is possibly a UIScrollView bug - see
+ // http://stackoverflow.com/questions/4123991/uiscrollview-disable-scrolling-while-rotating-on-iphone-ipad/8141423#8141423 ).
+ // This ends up corrupting the current page number, because the calculation
+ // 'current = x / width' is using the new value of 'width' before the
+ // pages have been resized/repositioned. To avoid this problem, we filter out
+ // calls to scrollViewDidScroll during rotation.
+ if (_isRotating)
+ return;
+
if (width == 0)
return; // not visible yet
@@ -1097,8 +1110,18 @@ static void saveDoc(char *current_path, fz_document *doc)
return YES;
}
+- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
+{
+ _isRotating = YES;
+}
+
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation)o
{
+ _isRotating = NO;
+
+ // We need to set these here, because during the animation we may use a wider
+ // size (the maximum of the landscape/portrait widths), to avoid clipping during
+ // the rotation.
[canvas setContentSize: CGSizeMake(fz_count_pages(doc) * width, height)];
[canvas setContentOffset: CGPointMake(current * width, 0)];
}