Extra White Space in Horizontal Scrollview of UITableViews - ios

Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[self colorWithHexString:#"d944f7"]];
self.pageControl = [[UIPageControl alloc] init];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 0, self.view.frame.size.width - 20, self.view.frame.size.height)];
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = NO;
self.scrollView.pagingEnabled = YES;
self.automaticallyAdjustsScrollViewInsets = NO;
self.scrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);
[self.view addSubview:self.scrollView];
}
- (void)reloadData
{
self.pageControl.numberOfPages = self.sectionsArray.count;
self.pageControl.currentPage = 0;
self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:(rand()%256)/256.0 green:(rand()%256)/256.0 blue:(rand()%256)/256.0 alpha:1];
self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:(rand()%256)/256.0 green:(rand()%256)/256.0 blue:(rand()%256)/256.0 alpha:1];
self.pageControl.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height - 20);
self.pageControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.pageControl];
self.scrollView.contentOffset = CGPointMake(0, 0);
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width*self.pageControl.numberOfPages, self.scrollView.frame.size.height);
NSMutableArray *array = [NSMutableArray array];
NSMutableArray *mvcs = [NSMutableArray array];
NSMutableArray *shadows = [NSMutableArray array];
for (int i = 0 ; i < self.pageControl.numberOfPages; i ++) {
UIView *shadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width - 20, self.scrollView.frame.size.height - 80)];
shadow.backgroundColor = [UIColor grayColor];
shadow.alpha = 1;
CGPoint pageCenter = CGPointMake((i + 0.5)*self.scrollView.frame.size.width, self.scrollView.frame.size.height/2.0);
shadow.center = pageCenter;
// [shadows addObject:shadow];
//[self.scrollView addSubview:shadow];
MDIMovingView *mv = [[MDIMovingView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width - 5, self.scrollView.frame.size.height - 80)];
mv.identity = 1;
mv.delegate = self;
mv.moveEnabled=NO;
mv.backgroundColor = [self colorWithHexString:#"e6e6e6"];
mv.center = pageCenter;
mv.layer.cornerRadius=10;
mv.clipsToBounds=NO;
[array addObject:mv];
[self.scrollView addSubview:mv];
UIView *topHeader=[[UIView alloc] initWithFrame:CGRectMake(0, 0, mv.frame.size.width, 50)];
[topHeader setRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:10.0];
[topHeader setBackgroundColor:[self colorWithHexString:#"dca2e8"]];
[mv addSubview:topHeader];
UIView *invisibleSeperator =[[UIView alloc] initWithFrame:CGRectMake(0, 50, mv.frame.size.width, 2)];
[invisibleSeperator setBackgroundColor:[self colorWithHexString:#"d944f7"]];
[mv addSubview:invisibleSeperator];
MDITableViewController *vc = [[MDITableViewController alloc] init];
[mvcs addObject:vc];
vc.objects = self.sortedTasksArray[i];
vc.delegate = self;
vc.dataSoure = self;
vc.movingViewDelegate = self;
[self addChildViewController:vc];
vc.view.frame = CGRectMake(5, 60, mv.frame.size.width - 10, mv.frame.size.height - 80);
[mv addSubview:vc.view];
}
self.shadowViews = shadows;
self.movingViews = array;
self.tableVCs = mvcs;
}
Here is what its doing- note the space between navigation bar and the movingview:

You have to disable the automaticallyAdjustsScrollViewInsets in your view controller
[self setAutomaticallyAdjustsScrollViewInsets:NO];
or in Storyboard
Uncheck the option

Related

how to get current image tag in scroll view?

//add the scrollview to the view
Friend_Request_Scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-60,70,120,140)];
[Friend_Request_Scroll setAlwaysBounceVertical:NO];
Friend_Request_Scroll.delegate=self;
Friend_Request_Scroll.pagingEnabled=YES;
[Friend_Request_Scroll setShowsHorizontalScrollIndicator:NO];
[Friend_Request_Scroll setShowsVerticalScrollIndicator:NO];
CGFloat xOrigin = 0;
for (int i = 0; i <[imageCollection count]; i++) {
Back_Request_Scroll=[[UIView alloc]init];
Back_Request_Scroll.frame=CGRectMake(xOrigin,Friend_Request_Scroll.frame.origin.y-135,120,140);
Back_Request_Scroll.backgroundColor=[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:0.5];
Back_Request_Scroll.clipsToBounds=YES;
[Friend_Request_Scroll addSubview:Back_Request_Scroll];
image = [[UIImageView alloc] initWithFrame:
CGRectMake(0, 0,
Back_Request_Scroll.frame.size.width,
Back_Request_Scroll.frame.size.height)];
[image sd_setImageWithURL:[imageCollection objectAtIndex:i] placeholderImage:[UIImage imageNamed:#""]];
image.tag=i;
[Back_Request_Scroll addSubview:image];
xOrigin= xOrigin+120;
image.userInteractionEnabled=YES;
}
Friend_Request_Scroll.contentSize = CGSizeMake(xOrigin,
0);
[self.view addSubview:Friend_Request_Scroll];
swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(swipeleft:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[image addGestureRecognizer:swipeleft];
swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(swiperight:)];
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[image addGestureRecognizer:swiperight];
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(self.view.frame.size.width/2-60,Friend_Request_Scroll.frame.size.height+Friend_Request_Scroll.frame.origin.y,image.frame.size.width,20);
pageControl.numberOfPages = [imageCollection count];
pageControl.currentPage = currentValue;
[pageControl addTarget:self action:#selector(changePage) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
Try this Delegate Method.This delegate will tell you that scrolling has finished.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
Try this code, you use recongizer object view tag.
- (void)viewDidLoad
{
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:scroll];
NSInteger i;
for (i=0; i<20; i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*90 + i*15, 300, 90)];
imageView.backgroundColor = [UIColor blackColor];
imageView.userInteractionEnabled = YES;
imageView.tag = i;
NSLog(#“image Tag = %d”, imageView.tag);
[scroll addSubview:imageView];
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
[imageView addGestureRecognizer: recognizer];
}
scroll.contentSize = CGSizeMake(320, 110*i);
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"Swipe received.");
NSLog(#“image Tag = %d”, recognizer.view.tag);
}
Update
No need swipe.
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (sender == scroll) {
int pageNum = (int)(scroll.contentOffset.x / scroll.frame.size.width);
NSLog(#"%d",pageNum);
//self.pagecontroller.currentPage =pageNum;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height)];
scroll.delegate = self;
scroll.pagingEnabled = YES;
[self.view addSubview:scroll];
CGFloat currentXOffset = 0;
NSInteger i;
for (i=0; i<3; i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(currentXOffset, 100, self.view.frame.size.width, 200)];
if (i == 0){
imageView.backgroundColor = [UIColor blackColor];
}else if (i == 1){
imageView.backgroundColor = [UIColor orangeColor];
}else if (i == 2){
imageView.backgroundColor = [UIColor grayColor];
}
imageView.userInteractionEnabled = YES;
imageView.tag = i;
currentXOffset = currentXOffset + imageView.frame.size.width;
[scroll addSubview:imageView];
// UISwipeGestureRecognizer *recognizer;
//
// recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
// [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
// [imageView addGestureRecognizer: recognizer];
}
scroll.contentSize = CGSizeMake(currentXOffset, self.view.frame.size.height);
}
Add tap gesture action to the image and you can get the tag using [sender tag]
I have Few ImageView each of them have tag and I have an array of images. when user tap on image then I get image tag and take action on it.
- (void)viewDidLoad
{
[super viewDidLoad];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:scroll];
NSInteger i;
for (i=0; i<20; i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*90 + i*15, 300, 90)];
imageView.backgroundColor = [UIColor blackColor];
imageView.userInteractionEnabled = YES;
imageView.tag = i;
NSLog(#“image Tag = %d”, imageView.tag);
[scroll addSubview:imageView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(findTheTag:)];
[imageView addGestureRecognizer:tap];
}
scroll.contentSize = CGSizeMake(320, 110*i);
}
- (void)findTheTag:(id)sender
{
NSLog(#“image Tag = %d”, sender.tag);
}

ios : how to add uiLabel on top of the background image?

I am trying to add the uiLabel on top of the uiImageVIew which is the background image. When it comes to adding the uiLabel on top of the uiImageView, the uilabel cannot be aded when testing and running. Would you please tell me the alternatives or precautions if doing so ?
The below is my code :
#implementation CoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
_container = [[UIView alloc] initWithFrame:[self.view bounds]];
[self setTapDemo :[UIImage imageNamed:#"cover_1_d.png"] ] ;
}
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"shaded_region.png"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, labelSize.width, labelSize.height)];
fromLabel.text = text;
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_imageShaded addSubview:fromLabel];
[imageView addSubview:fromLabel];
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[_container addSubview:fromLabel];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
}
Check This
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"images.jpg"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
// CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 300, 40)];
fromLabel.text = text;
fromLabel.textColor = [UIColor greenColor];
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
[imageView addSubview:fromLabel];
}
You are adding your UILabel more than once on different views. you should add it on a single view at a time;
//[_imageShaded addSubview:fromLabel]; // 1
//[imageView addSubview:fromLabel]; // 2
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
//[_container addSubview:fromLabel]; //3

How to add images in nested UIScrollview

I need to add images in scroll view multiple times. Am created a scrollview but images not append correctly in that.
My code is here :
-(void)sampleScroll
{
int x = 10;
int y = 20;
mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
mainScrollView.contentSize = CGSizeMake(50, (y + 95) * 5);
// further configure
[self.view addSubview: mainScrollView];
images = [[NSMutableArray alloc] initWithObjects:#"image0.jpg",#"image1.jpg",#"image2.jpg",#"image3.jpg", nil];
for(int i=0; i<[images count]; i++)
{
NSLog(#"%#",images);
UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 250, 150)];
scrollview.showsVerticalScrollIndicator=YES;
scrollview.scrollEnabled=YES;
scrollview.userInteractionEnabled=YES;
scrollview.backgroundColor = [UIColor whiteColor];
NSString *img = [images objectAtIndex:i];
NSLog(#"%#",img);
imageView.image = [UIImage imageNamed:#"image3.jpg"];
NSLog(#"%#",imageView.image);
scrollview.contentSize = CGSizeMake(1250,250);
[scrollview addSubview:imageView];
[mainScrollView addSubview:scrollview];
y=y+155;
//[self myscrollView];
}
}
Please give me a solution. Thanks in advance..
Frame adjustment needed,
int x = 10;
int y = 10;
UIScrollView * mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
mainScrollView.contentSize = CGSizeMake(mainScrollView.frame.size.width, mainScrollView.frame.size.height * COUNTS);
mainScrollView.pagingEnabled = YES;
for(int i = 0; i < COUNTS; i++)
{
UIScrollView * scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(x, y, mainScrollView.frame.size.width - 20.0, mainScrollView.frame.size.height - 20.0)];
scrollview.showsVerticalScrollIndicator = YES;
scrollview.scrollEnabled = YES;
scrollview.userInteractionEnabled = YES;
scrollview.backgroundColor = [UIColor whiteColor];
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(x,10.0, mainScrollView.frame.size.width - 40.0, mainScrollView.frame.size.height - 40.0)];
imageView.image = [UIImage imageNamed:#"owl.jpg"];
[scrollview addSubview:imageView];
[mainScrollView addSubview:scrollview];
y += mainScrollView.frame.size.height;
}
[self.view addSubview:mainScrollView];

How can i add multiple images to my scrollView in ios

i have scroll View with three slides,i want to add images to my scroll view.this is my code after this what do i need to add
- (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
[awesomeView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll release];
}
If you want to add Images horizontally (say 3 images), than you have to add scroll view with the width of 3*yourImageView.frame.size.width and than you can add those Image on (x=0,y=0),
(x = yourImageView.frame.size.width, y=0), and (x = 2*yourImageView.frame.size.width, y=0)
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, yourImageView.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
imageView1.frame = CGrectMake(0,0,imageView1.frame.size.width,imageView1.frame.size.height);
imageView2.frame = CGrectMake(0,imageView1.frame.size.width,imageView2.frame.size.width,imageView2.frame.size.height)
imageView3.frame = CGrectMake(0,2*imageView1.frame.size.width,imageView3.frame.size.width,imageView3.frame.size.height)
[scroll addSubview:imageView1];
[scroll addSubview:imageView2];
[scroll addSubview:imageView3];
enable horizontal scrolling

Issues with UISegmentedControl and switch statements

I am trying to develop this app and Im have a really hard time. Im am trying to use a UISegmentedControl to load a set of UIScrollViews which act as image filters.
Aside from having huge issues with the UIScrollViews (which is why a new one is creed individually in each segment) for some reason, clicking on segment 1 loads all 6 UIScrollViews and only lets me scroll the first one. When I select the last segment only 1 UIScrollView is loaded...
I really don't know what Im doing wrong here so any suggestions would be great!
Thanks very much,
Lawrence
~~~~ Code Below ~~~
- (void)layerSelected:(id)sender
{
int index = filterControl.selectedSegmentIndex;
switch (index)
{
case 0: if (scroll == nil)
{
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
scroll.delaysContentTouches = NO;
scroll.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll setContentOffset:currentPos1];
[self.view addSubview:scroll];
[scroll release];
}
else
{
//Set the position to the correct one
}
case 1: if (scroll1 == nil)
{
scroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll1.pagingEnabled = YES;
scroll1.delaysContentTouches = NO;
scroll1.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll1 addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll1.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll1 setContentOffset:currentPos2];
[self.view addSubview:scroll1];
[scroll1 release];
}
else
{
//Set the position to the correct one
}
case 2: if (scroll2 == nil)
{
scroll2 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll2.pagingEnabled = YES;
scroll2.delaysContentTouches = NO;
scroll2.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll2 addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll2.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll2 setContentOffset:currentPos3];
[self.view addSubview:scroll2];
[scroll2 release];
}
else
{
//Set the position to the correct one
}
case 3: if (scroll3 == nil)
{
scroll3 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll3.pagingEnabled = YES;
scroll3.delaysContentTouches = NO;
scroll3.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll3 addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll3.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll3 setContentOffset:currentPos4];
[self.view addSubview:scroll3];
[scroll3 release];
}
else
{
//Set the position to the correct one
}
case 4: if (scroll4 == nil)
{
scroll4 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll4.pagingEnabled = YES;
scroll4.delaysContentTouches = NO;
scroll4.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll4 addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll4.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll4 setContentOffset:currentPos5];
[self.view addSubview:scroll4];
[scroll4 release];
}
else
{
//Set the position to the correct one
}
case 5: if (scroll5 == nil)
{
scroll5 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll5.pagingEnabled = YES;
scroll5.delaysContentTouches = NO;
scroll5.userInteractionEnabled = YES;
NSInteger viewCount = 15;
for (int i = 0; i < viewCount; i++)
{
CGFloat yOrigin = i * self.view.frame.size.width;
UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
[filterViewOverlay setImage:[filterManager objectAtIndex:i]];
[scroll5 addSubview:filterViewOverlay];
[filterViewOverlay release];
}
scroll5.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height);
[self.scroll5 setContentOffset:currentPos6];
[self.view addSubview:scroll5];
[scroll5 release];
}
else
{
//Set the position to the correct one
}
}
}
You missed the break statements. Switch needs a break statement at the end of each case statement. Otherwise it executes all the code after the first susccessful match, regardless of the case values. ie.
switch (soemthing) {
case 1: // do something
break;
case 2: // do something else
break;
default:
}
Works as you expect. If you drop the breaks, then case 1 will execute all the code below it.

Resources