Knowledge Base - Limit horizontal page change when a page is zoomed

To limit horizontal scroll, we have to modify scrollViewDidScroll method (in PDFView class).

First, add DOUBLE_PAGE preprocessor macro: it will be 0 in single page mode and 1 in double page mode (it depends on m_view initialization in vopen method).

Now we have two cases: right to left or left to right mode.

Right to left:

scrollViewDidScroll method will become:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    if (m_cur_page + 1 < m_doc.pageCount && m_zoom > 1 && (self.contentOffset.x * m_scale + m_w > [m_view vGetPage:m_cur_page+1].GetX)){

#if DOUBLE_PAGE == 1

        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) || m_cur_page % 2 == 0)

#endif

            self.contentOffset = CGPointMake(([m_view vGetPage:m_cur_page+1].GetX / m_scale) - (m_w / m_scale), self.contentOffset.y);

    }

    if (m_cur_page > 0 && m_zoom > 1 && (self.contentOffset.x * m_scale < [m_view vGetPage:m_cur_page-1].GetX + [m_view vGetPage:m_cur_page-1].GetWidth)){

#if DOUBLE_PAGE == 1

        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) || m_cur_page % 2 != 0)

#endif

            self.contentOffset = CGPointMake(([m_view vGetPage:m_cur_page-1].GetX / m_scale) + ([m_view vGetPage:m_cur_page-1].GetWidth / m_scale), self.contentOffset.y);

    }   

    [m_view vMoveTo:self.contentOffset.x * m_scale :self.contentOffset.y * m_scale];

    [self refresh];

   CGRect rect = CGRectMake( self.contentOffset.x, self.contentOffset.y, m_w/m_scale, m_h/m_scale );

    m_child.frame = rect;

    m_child.backgroundColor = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0];

}

Left to right:

scrollViewDidScroll method will become:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    if (m_cur_page > 0 && m_zoom > 1 && (self.contentOffset.x * m_scale + m_w > [m_view vGetPage:m_cur_page-1].GetX)){

#if DOUBLE_PAGE == 1

        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) || m_cur_page % 2 == 0)

#endif

            self.contentOffset = CGPointMake(([m_view vGetPage:m_cur_page-1].GetX / m_scale) - (m_w / m_scale), self.contentOffset.y);

    }

    if (m_cur_page + 1 < m_doc.pageCount && m_zoom > 1 && (self.contentOffset.x * m_scale < [m_view vGetPage:m_cur_page+1].GetX + [m_view vGetPage:m_cur_page+1].GetWidth)){

#if DOUBLE_PAGE == 1

        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) || m_cur_page % 2 != 0)

#endif

            self.contentOffset = CGPointMake(([m_view vGetPage:m_cur_page+1].GetX / m_scale) + ([m_view vGetPage:m_cur_page+1].GetWidth / m_scale), self.contentOffset.y);

    }   

    [m_view vMoveTo:self.contentOffset.x * m_scale :self.contentOffset.y * m_scale];

    [self refresh];

   CGRect rect = CGRectMake( self.contentOffset.x, self.contentOffset.y, m_w/m_scale, m_h/m_scale );

    m_child.frame = rect;

    m_child.backgroundColor = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0];

}

Applies To

RadaeePDF SDK for iOS

Details

Created : 2015-02-02 17:34:12, Last Modified : 2015-02-03 11:22:16