2012-11-22 42 views
0

我有一個UIScrollview(水平)與UIview作爲一個子視圖,在這裏我可以能夠拖動scrollview內的UIView的scrollview的contentSize是2400當我拖動的UIView是不可見的,即,它是因爲我的scrollview寬度很小,我需要滾動scrollview使UIView可見。對於此我有使用的UIScrollView scrollrecttovisible方法

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

但仍然不能正常工作,請幫助我。

回答

3

在你的情況下,[myscroll scrollRectToVisible:myview.frame animated:YES];將無法​​工作,因爲MyView的myscroll的子視圖。 myview.frame將返回僅與myscroll有關的CGRect。

我的建議是,你可以通過獲得功能UIpageControl + UIScrollView。您可以將UIPageControl設置爲隱藏

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; 

注:

sidePager:UIPageControl對於右 - 左位置

UpAndDownPager:UIPageControl對於頂 - 底位置

+0

是否有可能沒有UIPageControl ..? –

+1

是的。您必須在與您的主視圖相關的滾動視圖中獲得確切的接觸點。 –

+0

myview.frame不會添加滾動區域的x位置。它將返回與其超級視圖相關的CGRect .. –

-2
scrollView.contentSize.width != 0 
&& 
scrollView.contentSize.height != 0 
相關問題