Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 19, 2011, 04:33 AM   #1
celric
macrumors newbie
 
Join Date: Jul 2011
Hi all,

Sorry im a newbie to ios. Is there any method in scrollview that will be called when user start scrolling the view? I've gone through some samples but most of them are using pagecontrol to do the. Basically what i want to achieve is that i got 50 images i put into the scrollview, and each image should have a label below. so when scroll on the scrollview i want to change the label text as well.

i have a scrollview in my secondviewcontroller.h
Code:
IBOutlet UIScrollView *scrollView1;
Here is how i create image & make subviews in viewdidload of my secondviewcontroller.m
Code:
const CGFloat kScrollObjHeight	= 800;
const CGFloat kScrollObjWidth	= 600;
const NSUInteger kNumImages	= 50;

- (void)viewDidLoad {
        [scrollView1 setCanCancelContentTouches:NO];
	scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
	scrollView1.clipsToBounds = YES;
	scrollView1.scrollEnabled = YES;
	scrollView1.pagingEnabled = YES;

        NSUInteger i;
	for (i = 1; i <= kNumImages; i++)
	{
		NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
		UIImage *image = [UIImage imageNamed:imageName];
		UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        
		CGRect rect = imageView.frame;
		rect.size.height = kScrollObjHeight;
		rect.size.width = kScrollObjWidth;
		imageView.frame = rect;
		imageView.tag = i;	// tag images for later use when we place them in serial fashion
		[scrollView1 addSubview:imageView];
                [imageView release];
                [self layoutScrollImages:0];
        }
}
and here is where i split out the images.
Code:
- (void)layoutScrollImages:(int)page
{
    if (page < 0)
        return;
    if (page >= kNumImages)
        return;

	UIImageView *view = nil;
	NSArray *subviews = [scrollView1 subviews];

	CGFloat curXLoc = 0;
        
	for (view in subviews)
	{
		if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
		{
			CGRect frame = view.frame;
			frame.origin = CGPointMake(curXLoc, 0);
			view.frame = scrollView1.frame;
			curXLoc += (kScrollObjWidth);     
		}
	}
}
I only have a ScrollView & a Label in my .xib, but i want to change the text when the viewchange. what i got now just able to scroll the view but got no idea how to change the label text as viewchange. Any help would be greatly appreciated. Thanks in advance.

Here is how i create image & make subviews in viewdidload of my secondviewcontroller.m
Code:
const CGFloat kScrollObjHeight	= 800;
const CGFloat kScrollObjWidth	= 600;
const NSUInteger kNumImages	= 50;

- (void)viewDidLoad {
        [scrollView1 setCanCancelContentTouches:NO];
	scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
	scrollView1.clipsToBounds = YES;
	scrollView1.scrollEnabled = YES;
	scrollView1.pagingEnabled = YES;

        NSUInteger i;
	for (i = 1; i <= kNumImages; i++)
	{
		NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
		UIImage *image = [UIImage imageNamed:imageName];
		UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        
		CGRect rect = imageView.frame;
		rect.size.height = kScrollObjHeight;
		rect.size.width = kScrollObjWidth;
		imageView.frame = rect;
		imageView.tag = i;	// tag images for later use when we place them in serial fashion
		[scrollView1 addSubview:imageView];
                [imageView release];
       }
       [self layoutScrollImages:0];
}
misplacement of the line just now.

Last edited by robbieduncan; Jul 19, 2011 at 06:46 AM. Reason: Please use the edit post functionality instead of posting again: I have merged the posts
celric is offline   0 Reply With Quote
Old Jul 19, 2011, 07:09 AM   #2
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
UIScrollView has a delegate protocol. Look at scrollViewDidScroll.
PhoneyDeveloper is offline   0 Reply With Quote
Old Jul 19, 2011, 09:50 AM   #3
celric
Thread Starter
macrumors newbie
 
Join Date: Jul 2011
Quote:
Originally Posted by PhoneyDeveloper View Post
UIScrollView has a delegate protocol. Look at scrollViewDidScroll.
I think i found the solution, thanks for the info! appreciate it
celric is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
help with dragging a UIImageView on screen mandude iPhone/iPad Programming 3 Nov 28, 2011 12:05 PM
Backup help! robkot iPhone Tips, Help and Troubleshooting 2 Dec 1, 2010 12:04 AM
help with excel for mac 2008 damiang72 Mac Applications and Mac App Store 0 Nov 14, 2010 06:19 AM
video editing help WoblierRex Digital Video 0 Nov 8, 2010 09:23 PM


All times are GMT -5. The time now is 11:32 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC