PDA

View Full Version : UIScrollView + pagingEnabled, scroll half a page?




iphoneSDKrules
Jan 14, 2009, 05:32 PM
Hello,

can anyone tell me if it is possible, to scroll half a page in a UIScrollView with pagingEnabled = true.

As far as I know, the amount of scrolling when pagingEnabled depends on the frame size of the ScrollView, so it scrolls exactly one page.What I'd like to do is scrolling exactly half a page: my ScrollView contains two images on each 'page' and after scrolling I don't want to display the next two images, but the second image of the previous page + the first image of the next page and so on...

I'd be so glad if anyone could tell me how to do so.

thanks for your help, kate :)



walty
Jan 14, 2009, 09:37 PM
hm.. I have seen such scenario (as a bug) in uitableview, but not sure if it worked the same as uiscrollview.

have u tried to make the frame size of the scrollview TWICE the size of screen? in that way, the second half may never be scrolled to.

zkiraly
Jan 15, 2009, 11:20 AM
I am also interested in the same. Right now I have a workaround in place, but being able to page arbitrary distances would be nice.

Zsolt

dejo
Jan 15, 2009, 11:42 AM
I am also interested in the same. Right now I have a workaround in place, but being able to page arbitrary distances would be nice
That doesn't sound like paging to me, which, as I understand it, is scrolling non-arbitrary distances.

My suggestion to everyone would be to set pagingEnabled = NO and scrollingEnabled = NO and then capture the swipe events and then call scrollRectToVisible to scroll to where you want it. I'm not certain this will work but it's worth a shot.

zkiraly
Jan 15, 2009, 02:26 PM
My suggestion to everyone would be to set pagingEnabled = NO and scrollingEnabled = NO and then capture the swipe events and then call scrollRectToVisible to scroll to where you want it. I'm not certain this will work but it's worth a shot.

Thanks for the suggestion. Actually, that's what I do now. But there is no 'bounce' at the end, like in the weather app.

I think this is still 'paging.' Imagine the weather app, but zoomed out, so you see a portion of the adjoining pages as well. That's kinda what I'd like to accomplish in my own app.

iphoneSDKrules
Jan 16, 2009, 11:12 AM
My suggestion to everyone would be to set pagingEnabled = NO and scrollingEnabled = NO and then capture the swipe events and then call scrollRectToVisible to scroll to where you want it. I'm not certain this will work but it's worth a shot.

Thank you! That solves my problem!
I set paginEnabled + scrollingEnabled to NO and capture swipes using the touchesBegan and touchesEnded methods. Depending on a positive or negative yDistance between the two touch locations, I call the scrollRectToVisible in order to scroll half a page forward or backward, which works really well! :cool:

coconutdj
Mar 12, 2009, 04:45 AM
hi iphoneSdkRules,
i have the same problem , i want to scroll a half page, can you send me that piece of code to see hot to do this ?
" I set paginEnabled + scrollingEnabled to NO and capture swipes using the touchesBegan and touchesEnded methods. Depending on a positive or negative yDistance between the two touch locations, I call the scrollRectToVisible in order to scroll half a page forward or backward, which works really well! "

Thanks
coconut_dj@yahoo.com

iphoneSDKrules
Mar 25, 2009, 08:16 AM
hi, this is what i did in touchesBegan & touchesEnded methods:


#define SCROLLOFFSET 60

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"TOUCHES BEGAN!");

UITouch* touch = [touches anyObject];
touchDown = [touch locationInView:self.view];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
NSLog(@"TOUCHES ENDED!");

UITouch* touch = [touches anyObject];
touchUp = [touch locationInView:[[self.view subviews] objectAtIndex:0]];

//calculate dragging distance
double dy = touchUp.y - touchDown.y;
double dx = touchUp.x - touchDown.x;

NSLog(@"touchDown x: %d, y: %d", touchDown.x, touchDown.y);
NSLog(@"touchUp x: %d, y:%d", touchUp.x, touchUp.y);
NSLog(@"distance between touches: %d", dy);

if(abs(dy) > SCROLLOFFSET)
{
if(dy < 0)
[self scrollForward];
else
[self scrollBackward];
}
}


touchUp and touchDown are both CGPoints, the scrollForward and scrollBackward are used to call the scrollRectToVisible method with a calculated offset.

hope that helps

Goblin2099
Apr 7, 2009, 03:20 AM
Check out this post (http://www.inediblesoftware.com/blog/2009/04/05/uiscrollview-paging-hack/) for another way to accomplish half screen paging