0

I have a uiscrollview and I put 4 uiviews to make an option. I put label 1 for uiview1 and label 2 for uiview2, for uiview 3 i put label 3 and uiview4 i put label 4.

After that I hide the 4 uiview so everytime I pulldown the screen the 4 uiviews will display base on how far the user pull.

Can anyone give an example on how to display the which uiview is selected, when you pull the screen in ios iphone?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Aragon
  • 59
  • 2
  • 8

2 Answers2

0

For your reference, you can see a sample implementation of a page control from here. http://developer.apple.com/library/ios/#samplecode/PageControl/

For the implementation you want, to your surprise, the scrollview's width is actually smaller than 320 (or 480). The magic property to set is:

scrollView.clipsToBounds = NO The only problem with this implementation is that the scrollview get no touch events if the touch is outside the bounds of the scrollView. This can be fix by passing its parent hitTest event to scrollView.

Just to link to to a better explanation: UIScrollView horizontal paging like Mobile Safari tabs

Slightly different from what I recommend but does the same thing.

Edit:

I have a small project called LXPagingViews that does the above, hopefully in an out of the box manner (Do drop me a pull request or feedback in issue): https://github.com/lxcid/LXPagingViews

Bhrigesh
  • 861
  • 1
  • 7
  • 14
  • Why are you plagiarizing? The answer and the open source drop-in class is from @lxcid, not you. http://stackoverflow.com/questions/5618780/uiscrollview-with-pagination-showing-part-of-the-previous-following-pages/5618930#5618930 – Bourne Nov 06 '13 at 09:58
0

You can use contentOffset of scroll View to find how far user pulled scroll View.

Use scroll View delegate Method:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

By checking frames of your views & scrollView contentOffset, you can determine which view is visible (i.e. uiview1, uiview2,..).

Edit:

Your logic should be like this:

if(uiview1.frame.origin.y - scrollView.contentOffset.y > uiview1.frame.origin.y + uiview1.frame.size.height)
{
    //your logic for selection of uiview1
}else if.......

Apply this conditions from last view to first view.

OnkarK
  • 3,745
  • 2
  • 26
  • 33
  • Can you give an example? – Aragon Aug 20 '13 at 06:36
  • Hi @OMK, Can you give further example when I stop the pull and the (uiview1,uiview2...) content will display somewhere in the screen. I am a newbie in ios and I am not familiar on the coding. – Aragon Aug 20 '13 at 07:21
  • After pulling/dragging scroll view, to visible uiview you want to mark as a selected. right? – OnkarK Aug 20 '13 at 08:16
  • yup, its like if(scrollView.contentOffset.y == -60) selectedLabel.text = uiview1. hmmmm I don't know the exact script. – Aragon Aug 20 '13 at 08:32
  • I have given some sample logic try it and let me know. – OnkarK Aug 20 '13 at 09:09
  • I already solve that issue. below is my solution if ((int) scrollView.contentOffset.y > -89{ NSLOG(@"answer here"); } But What I am try to say is that inside in my if statement the content in uiview1 should display in my "textLabel" – Aragon Aug 20 '13 at 09:39
  • your uiview1 is object of label. textLabel.text = uiview1.text – OnkarK Aug 20 '13 at 09:46