Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 19, 2011, 05: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 07: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, 08:09 AM   #2
PhoneyDeveloper
macrumors 68030
 
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, 10: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

Similar Threads
thread Thread Starter Forum Replies Last Post
How do you use autolayout to position a button at the bottom of a scrollview? whitedragon101 iPhone/iPad Programming 1 Jun 1, 2014 04:38 PM
Scrolling textview + scrollview problem solinari6 iPhone/iPad Programming 4 Mar 27, 2014 03:17 PM
scrollview scrolling when it shouldn't straber iPhone/iPad Programming 3 Sep 18, 2012 01:37 AM

Forum Jump

All times are GMT -5. The time now is 02:55 PM.

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

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