2010-09-23 5 views
4

Je suis actuellement à la recherche de façons d'ajouter plusieurs UIImageView à un seul UIScrollView. Le UIScrollView sera 1,5 fois la taille de l'un des UIImageViews. Je veux créer un effet de défilement pour parcourir quelques petites images dans une application iPad. Est-ce que quelqu'un sait comment y parvenir?Ajouter UIImageViews à UIScrollView

Répondre

11
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(/*FRAME*/)]; // this makes the scroll view - set the frame as the size you want to SHOW on the screen 
[scrollView setContentSize:CGSizeMake(/*SIZE OF THE CONTENT*/)]; // if you set it to larger than the frame the overflow will be hidden and the view will scroll 

/* you can do this bit as many times as you want... make sure you set each image at a different origin */ 
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"/*IMAGE*/"]]; // this makes the image view 
[imageView setFrame:CGRectMake(/*SET AS 2/3 THE SIZE OF scrollView AND EACH IMAGE NEXT TO THE LAST*/)]; // this makes the image view display where you want it and at the right size 
[scrollView addSubview:imageView]; // this adds the image to the scrollview 
/* end adding image */ 

[self.view addSubview:scrollView]; 
+0

OK, vous avez mec! Je vais essayer! – TheLearner

+0

Bonne explication merci mon pote. Y at-il de toute façon forcer les barres de défilement à être visibles à tout moment? – TheLearner

+0

Ou une façon de le faire animer ou quelque chose que l'utilisateur sait qu'ils peuvent faire défiler – TheLearner

Questions connexes