Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-11-2010, 08:38 PM   #1 (permalink)
Registered Member
 
bladeolson's Avatar
 
Join Date: Aug 2008
Posts: 31
bladeolson is on a distinguished road
Send a message via AIM to bladeolson
Default controlling view with buttons in ScrollView?

I have a scrollview that contains 15 separate views. I can page by swiping left or right. Works great.

I want to add a LEFT and RIGHT button instead of swiping. Any ideas how I might do this?

blade
bladeolson is offline   Reply With Quote
Old 07-11-2010, 10:22 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 22
meris is on a distinguished road
Default

Quote:
Originally Posted by bladeolson View Post
I have a scrollview that contains 15 separate views. I can page by swiping left or right. Works great.

I want to add a LEFT and RIGHT button instead of swiping. Any ideas how I might do this?

blade

I believe the property you are looking for is contentOffset. That determines where in the ScrollView is currently displayed. So on a paging thing the code would look like this.

Code:
-(IBAction)goRight:(id)sender {
CGPoint curr = [scrollView contentOffset];
/* Page size would normally be 320 or something similar, we want one full page */
curr.x += pageSize;
[scrollView setContentOffset:curr];
}
It would be the same thing for goLeft, just -= instead of +=
meris is offline   Reply With Quote
Old 07-11-2010, 11:42 PM   #3 (permalink)
Registered Member
 
bladeolson's Avatar
 
Join Date: Aug 2008
Posts: 31
bladeolson is on a distinguished road
Send a message via AIM to bladeolson
Default thanks!

Thanks. That was very helpful... It at least it got me on the right track.

thank you.

I got it to work by using...

Code:
- (IBAction)leftPage:(id)sender {
	
	
	int page = [controlPageControl currentPage];
	// update the scroll view to the appropriate page
	CGRect frame = controlScrollView.frame;
	frame.origin.x = frame.size.width * (page-1);
	frame.origin.y = 0;
	
	[controlScrollView scrollRectToVisible:frame animated:YES];
	
	[controlPageControl setCurrentPage:page-1];
	
	[leftSound play];	
	
	
}


Quote:
Originally Posted by meris View Post
I believe the property you are looking for is contentOffset. That determines where in the ScrollView is currently displayed. So on a paging thing the code would look like this.

Code:
-(IBAction)goRight:(id)sender {
CGPoint curr = [scrollView contentOffset];
/* Page size would normally be 320 or something similar, we want one full page */
curr.x += pageSize;
[scrollView setContentOffset:curr];
}
It would be the same thing for goLeft, just -= instead of +=
bladeolson is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 341
16 members and 325 guests
akphyo, alexP, appservice, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, mariano_donati, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0