I am building an app where part of it allows you to scroll through different images to overlay. I have a segmented control to make a sort of layering system where each segment allows you to scroll through the images again and build up layers. For some reason first image always sticks and when I return to a layer, the view is reset to its original position but also saves the last position?
Here is my code.
- (void)layerControl
{
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger viewCount = 8;
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.view addSubview:scroll];
[scroll autorelease];
//Determine the current filter in view of the scroll view
CGFloat pageWidth = scroll.frame.size.width;
int cFilter = floor((scroll.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
currentFilter = cFilter;
}
//Method to add a filter to the page
- (void)addFilter:(id)sender
{
UISegmentedControl *filterController = (UISegmentedControl *)sender;
switch ([filterController selectedSegmentIndex])
{
case 0: self.layerControl;
case 1: self.layerControl;
case 2: self.layerControl;
case 3: self.layerControl;
case 4: self.layerControl;
case 5: self.layerControl;
default: NULL;
}
}