Vfr-Reader UIScrollView从左到右

时间:2013-03-14 10:13:24

标签: uiscrollview

我正在使用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.我缺少的东西可以帮助我。

0 个答案:

没有答案