0

我有一个UIScrollview(水平)UIview作为子视图,在这里我可以将 uiview 拖到里面scrollview,contentSizescrollview是 2400。当我拖动 uiview 时它是不可见的,即它在滚动视图内,因为我的滚动视图宽度很小,我需要滚动scrollview使 UIView 可见。为此我有使用

[myscroll scrollRectToVisible:myview.frame animated:YES];

但它仍然无法正常工作,请帮助我。

4

2 回答 2

3

In Your case,[myscroll scrollRectToVisible:myview.frame animated:YES]; will not work because of myview is a sub-view of myscroll. myview.frame will return the CGRect which is only related to the myscroll.

My suggestion is , you can acheive the functionality through UIpageControl + UIScrollView . You can set UIPageControl as Hidden.

SampleCode

int page = sidePager.currentPage + 1;
CGRect frame = scroller.frame;
frame.origin.x = frame.size.width * page;

if (0 != UpAndDownPager.currentPage) {

     frame.origin.y = frame.size.height * (UpAndDownPager.currentPage + 1 );
}

scroller scrollRectToVisible:frame animated:YES];       
sidePager.currentPage = sidePager.currentPage + 1;  

Note:

sidePager: UIPageControl For Right-Left position

UpAndDownPager: UIPageControl For Top-Bottom position

于 2012-11-22T08:09:04.167 回答
-2
scrollView.contentSize.width != 0 
&&
scrollView.contentSize.height != 0 
于 2016-05-18T07:28:27.523 回答