Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iphoneSDKrules

macrumors newbie
Original poster
Aug 21, 2008
9
0
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

macrumors member
Jul 15, 2008
33
0
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

macrumors newbie
Jan 15, 2009
2
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors newbie
Jan 15, 2009
2
0
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

macrumors newbie
Original poster
Aug 21, 2008
9
0
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

macrumors newbie
Mar 12, 2009
1
0
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

macrumors newbie
Original poster
Aug 21, 2008
9
0
hi, this is what i did in touchesBegan & touchesEnded methods:

PHP:
#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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.