I have a code that I want to modify in order to scale. Now my application only performs horizontal scrolling, but not scaling.
I missed something because I tried "viewForZoomingInScrollView:" without success. How can I zoom in?
thanks
and implementation:
#import "IntroductionViewController.h" #define kIGUIScrollViewImagePageIdentifier @"kIGUIScrollViewImagePageIdentifier" #define kIGUIScrollViewImageDefaultPageIdentifier @"Default" @implementation IntroductionViewController @synthesize scrollView; - (int)getScrollViewWidth { return ([contentArray count] * scrollWidth); } - (void)setWidth:(int)width andHeight:(int)height { scrollWidth = width; scrollHeight = height; if (!width || !height) rectScrollView = [[UIScreen mainScreen] applicationFrame]; else rectScrollView = CGRectMake(0, 0, width, height); } - (void)setSizeFromParentView:(UIScrollView *)scView { scrollWidth = scView.frame.size.width; scrollHeight = scView.frame.size.height; rectScrollView = CGRectMake(0, 0, scrollWidth, scrollHeight); } - (void)setContentArray:(NSArray *)images { contentArray = images; } - (void)setBackGroudColor:(UIColor *)color { bcgColor = color; } - (void)enablePositionMemoryWithIdentifier:(NSString *)identifier { rememberPosition = NO; if (!identifier) identifier = kIGUIScrollViewImageDefaultPageIdentifier; positionIdentifier = identifier; } - (void)enablePositionMemory { [self enablePositionMemoryWithIdentifier:nil]; } - (UIScrollView *)getWithPosition:(int)page { if (!contentArray) { contentArray = [[[NSArray alloc] init] autorelease]; } if (page > [contentArray count]) page = 0; if (!scrollWidth || !scrollHeight) { rectScrollView = [[UIScreen mainScreen] applicationFrame]; scrollWidth = rectScrollView.size.width; scrollHeight = rectScrollView.size.height; } rectScrollView = CGRectMake(0, 0, scrollWidth, scrollHeight); self.scrollView = [[UIScrollView alloc] initWithFrame:rectScrollView]; self.scrollView.contentSize = CGSizeMake([self getScrollViewWidth], scrollHeight); if (!bcgColor) bcgColor = [UIColor blackColor]; self.scrollView.backgroundColor = bcgColor; self.scrollView.alwaysBounceHorizontal = YES; self.scrollView.contentOffset = CGPointMake(page * scrollWidth, 0); self.scrollView.pagingEnabled = YES; UIView *main = [[[UIView alloc] initWithFrame:rectScrollView] autorelease]; int i = 0; for (UIImage *img in contentArray) { UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = img; imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); imageView.backgroundColor = [UIColor blackColor]; float ratio = img.size.width/rectScrollView.size.width; CGRect imageFrame = CGRectMake(i, 0, rectScrollView.size.width, (img.size.height / ratio)); imageView.frame = imageFrame; [self.scrollView addSubview:(UIView *)imageView]; i += scrollWidth; [imageView release]; } [main addSubview:scrollView]; //if (margin) [margin release]; [self.scrollView release]; [self.scrollView release]; return (UIScrollView *)main; } - (UIScrollView *)get { return [self getWithPosition:0]; } - (UIScrollView *)getWithPositionMemory { [self enablePositionMemory]; return [self getWithPosition:[[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@", kIGUIScrollViewImagePageIdentifier, kIGUIScrollViewImageDefaultPageIdentifier]] intValue]]; } - (UIScrollView *)getWithPositionMemoryIdentifier:(NSString *)identifier { [self enablePositionMemoryWithIdentifier:identifier]; return [self getWithPosition:[[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@", kIGUIScrollViewImagePageIdentifier, positionIdentifier]] intValue]]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)sv { int page = sv.contentOffset.x / sv.frame.size.width; if (rememberPosition) { [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%d", page] forKey:[NSString stringWithFormat:@"%@%@", kIGUIScrollViewImagePageIdentifier, positionIdentifier]]; [[NSUserDefaults standardUserDefaults] synchronize]; } } - (NSArray *)getImages { NSMutableArray *arr = [[[NSMutableArray alloc] init] autorelease]; // codice per intercettare la lingua impostata dall utente NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; NSString *currentLanguage = [languages objectAtIndex:0]; NSLog(@"Codice lingua %@", currentLanguage); if( [currentLanguage isEqualToString:@"es"] ){ [arr addObject:[UIImage imageNamed:@"image1-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image2-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image3-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image4-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image5-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image6-intro.jpg"]]; return (NSArray *)arr; } else { [arr addObject:[UIImage imageNamed:@"image1-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image2-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image3-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image4-intro.jpg"]]; [arr addObject:[UIImage imageNamed:@"image5-intro.jpg"]]; return (NSArray *)arr; } } /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //codice per mettere il titolo come immagine UIImage *titolo = [UIImage imageNamed: @"introTitle.png"]; UIImageView *titoloView = [[UIImageView alloc] initWithImage: titolo]; self.navigationItem.titleView = titoloView; IntroductionViewController *svimage = [[IntroductionViewController alloc] init]; [svimage setContentArray:[self getImages]]; [svimage setSizeFromParentView:scrollView]; [self.view addSubview:[svimage getWithPosition:0]]; [svimage release]; [titoloView release]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { NSLog(@"memoria view"); // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end
source share