1

我正在使用 Vfr-Reader 源代码,在这里我无法从左到右滚动滚动视图,默认情况下它是从右到左。我怎样才能实现这一点我尝试了很多设置偏移量,还尝试将条件与原点放在一起。

- (void)showDocumentPage:(NSInteger)page
{
if (page != currentPage) // Only if different
{
NSInteger minValue; NSInteger maxValue;
NSInteger maxPage = [document.pageCount integerValue];
NSInteger minPage = 1;

if ((page < minPage) || (page > maxPage)) return;

if (maxPage <= PAGING_VIEWS) // Few pages
{
minValue = minPage;
maxValue = maxPage;
}
else // Handle more pages
{
minValue = (page - 1);
maxValue = (page + 1);

if (minValue < minPage)
{minValue++; maxValue++;}
else
if (maxValue > maxPage)
{minValue--; maxValue--;}
}

NSMutableIndexSet *newPageSet = [NSMutableIndexSet new];

NSMutableDictionary *unusedViews = [contentViews mutableCopy];

CGRect viewRect = CGRectZero; viewRect.size = theScrollView.bounds.size;

for (NSInteger number = minValue; number <= maxValue; number++)
{
NSNumber *key = [NSNumber numberWithInteger:number]; // # key

ReaderContentView *contentView = [contentViews objectForKey:key];

if (contentView == nil) // Create a brand new document content view
{
NSURL *fileURL = document.fileURL; NSString *phrase = document.password; // Document properties

contentView = [[ReaderContentView alloc] initWithFrame:viewRect fileURL:fileURL page:number password:phrase];

[theScrollView addSubview:contentView]; [contentViews setObject:contentView forKey:key];

contentView.message = self; [newPageSet addIndex:number];
}
else // Reposition the existing content view
{
contentView.frame = viewRect; [contentView zoomReset];

[unusedViews removeObjectForKey:key];
}

viewRect.origin.x += viewRect.size.width;
}

[unusedViews enumerateKeysAndObjectsUsingBlock: // Remove unused views
^(id key, id object, BOOL *stop)
{
[contentViews removeObjectForKey:key];

ReaderContentView *contentView = object;

[contentView removeFromSuperview];
}
];

unusedViews = nil; // Release unused views

CGFloat viewWidthX1 = viewRect.size.width;
CGFloat viewWidthX2 = (viewWidthX1 * 2.0f);

CGPoint contentOffset = CGPointZero;

if (maxPage >= PAGING_VIEWS)
{
if (page == maxPage)
contentOffset.x = viewWidthX2;
else
if (page != minPage)
contentOffset.x = viewWidthX1;
}
else
if (page == (PAGING_VIEWS - 1))
contentOffset.x = viewWidthX1;

if (CGPointEqualToPoint(theScrollView.contentOffset, contentOffset) == false)
{
theScrollView.contentOffset = contentOffset; // Update content offset
}

if ([document.pageNumber integerValue] != page) // Only if different
{
document.pageNumber = [NSNumber numberWithInteger:page]; // Update page number
}

NSURL *fileURL = document.fileURL; NSString *phrase = document.password; NSString *guid = document.guid;

if ([newPageSet containsIndex:page] == YES) // Preview visible page first
{
NSNumber *key = [NSNumber numberWithInteger:page]; // # key

ReaderContentView *targetView = [contentViews objectForKey:key];

[targetView showPageThumb:fileURL page:page password:phrase guid:guid];

[newPageSet removeIndex:page]; // Remove visible page from set
}

[newPageSet enumerateIndexesWithOptions:NSEnumerationReverse usingBlock: // Show previews
^(NSUInteger number, BOOL *stop)
{
NSNumber *key = [NSNumber numberWithInteger:number]; // # key

ReaderContentView *targetView = [contentViews objectForKey:key];

[targetView showPageThumb:fileURL page:number password:phrase guid:guid];
}
];

newPageSet = nil; // Release new page set

[mainPagebar updatePagebar]; // Update the pagebar display

[self updateToolbarBookmarkIcon]; // Update bookmark

currentPage = page; // Track current page number
}

}

我改变了这个

if (maxPage <= PAGING_VIEWS) // Few pages
{
minValue = minPage;
maxValue = maxPage;
}
else // Handle more pages
{
minValue = (page - 1);
maxValue = (page + 1);

if (minValue < minPage)
{minValue++; maxValue++;}
else
if (maxValue > maxPage)
{minValue--; maxValue--;}
}
</pre>

一旦你在当前页面上,我得到了正确的 minValue 和 max 值来加载左页和右页,例如,如果我在第 3 页,那么左边应该是 4,右边应该是 2但它没有加载这些,而是​​加载左侧 2 和右侧 5。我缺少的东西可以帮助我。

4

0 回答 0