0
votes

I have an UIScrollview(Horizontal) with a UIview as a subview, here i can able to drag the uiview inside the scrollview, the contentSize of scrollview is 2400. When i dragging that uiview it's not visible i.e, it's going inside the scrollview because my scrollview width is small, i need to scroll the scrollview to make visible of UIView. For this i have use

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

but still its not working, please help me out.

2

2 Answers

3
votes

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

-2
votes
scrollView.contentSize.width != 0 
&&
scrollView.contentSize.height != 0