Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright, this should be easy, though a bit of coding is needed. Start out with a simple <strong>view based</strong> app template.</p> <p>I don't know where the images come from so I just put all the images to be shown in the resources folder. </p> <p>The view controller <code>PictureViewController</code> will accept an array of UIImages and should be presented modally. I'll post the code below.</p> <p>The code to show the <code>PictureViewController</code> is placed in the view controller created by the template. I just added a simple UIButton to the view to trigger an action which looks something like this:</p> <pre><code>- (IBAction)onShowPictures { // Load all images from the bundle, I added 14 images, named 01.jpg ... 14.jpg NSMutableArray *images = [NSMutableArray array]; for (int i = 1; i &lt;= 14; i++) { [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%02d.jpg", i]]]; } PictureViewController *picViewController = [[PictureViewController alloc] initWithImages:images]; [self presentModalViewController:picViewController animated:YES]; [picViewController release]; } </code></pre> <p>The view controller's view was created with interface builder, looking like this:</p> <h2>PictureViewController.xib</h2> <p><img src="https://i.stack.imgur.com/qCPyf.png" alt="enter image description here"></p> <p><strong>View Hierarchy</strong></p> <p><img src="https://i.stack.imgur.com/fK2bk.png" alt="enter image description here"></p> <p>The fullscreen image is linked to an outlet <code>fullScreenImage</code> seen in the following header file. Actions are connected as well.</p> <p>I've set the fullscreen imageView's content mode to Aspect Fit.</p> <p>The Thumbnails will be added dynamically with code. Here's the view controller's code</p> <h2>PictureViewController.h</h2> <pre><code>@interface PictureViewController : UIViewController { NSMutableArray *imageViews; NSArray *images; UIImageView *fullScreenImage; int currentPage; } @property (nonatomic, retain) NSMutableArray *imageViews; @property (nonatomic, retain) NSArray *images; @property (nonatomic, retain) IBOutlet UIImageView *fullScreenImage; - (id)initWithImages:(NSArray *)images; - (IBAction)onClose; - (IBAction)onNextThumbnails; - (IBAction)onPreviousThumbnails; @end </code></pre> <h2>PictureViewController.m</h2> <p>The define <code>MAX_THUMBNAILS</code> on top defines the maximum of thumbnails seen. A <code>UITapGestureRecognizer</code> will take care of the tap events for the thumbnails. Adjust the <code>CGRectMake</code> in <code>setupThumbnailImageViews</code> to position the thumbnails as you wish. This controller is just a basic approach without orientation support. </p> <pre><code>#import "PictureViewController.h" #define MAX_THUMBNAILS 6 @interface PictureViewController () - (void)showSelectedImageFullscreen:(UITapGestureRecognizer *)gestureRecognizer; - (void)setupThumbnailImageViews; - (void)setThumbnailsForPage:(int)aPage; - (UIImage *)imageForIndex:(int)anIndex; @end @implementation PictureViewController @synthesize imageViews, images, fullScreenImage; - (id)initWithImages:(NSArray *)someImages { self = [super init]; if (self) { self.images = someImages; self.imageViews = [NSMutableArray array]; currentPage = 0; } return self; } - (void)viewDidLoad { self.fullScreenImage.image = [images objectAtIndex:0]; [self setupThumbnailImageViews]; [self setThumbnailsForPage:0]; } - (void)showSelectedImageFullscreen:(UITapGestureRecognizer *)gestureRecognizer { UIImageView *tappedImageView = (UIImageView *)[gestureRecognizer view]; fullScreenImage.image = tappedImageView.image; } - (void)setupThumbnailImageViews { for (int i = 0; i &lt; MAX_THUMBNAILS; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20.0, 166.0 + (130.0 * i), 130.0, 90.0)]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showSelectedImageFullscreen:)]; tapGestureRecognizer.numberOfTapsRequired = 1; tapGestureRecognizer.numberOfTouchesRequired = 1; [imageView addGestureRecognizer:tapGestureRecognizer]; [tapGestureRecognizer release]; imageView.userInteractionEnabled = YES; [imageViews addObject:imageView]; [self.view addSubview:imageView]; } } - (void)setThumbnailsForPage:(int)aPage { for (int i = 0; i &lt; MAX_THUMBNAILS; i++) { UIImageView *imageView = (UIImageView *)[imageViews objectAtIndex:i]; UIImage *image = [self imageForIndex:aPage * MAX_THUMBNAILS + i]; if (image) { imageView.image = image; imageView.hidden = NO; } else { imageView.hidden = YES; } } } - (UIImage *)imageForIndex:(int)anIndex { if (anIndex &lt; [images count]) { return [images objectAtIndex:anIndex]; } else { return nil; } } #pragma mark - #pragma mark user interface interaction - (IBAction)onClose { [self dismissModalViewControllerAnimated:YES]; } - (IBAction)onNextThumbnails { if (currentPage + 1 &lt;= [images count] / MAX_THUMBNAILS) { currentPage++; [self setThumbnailsForPage:currentPage]; } } - (IBAction)onPreviousThumbnails { if (currentPage - 1 &gt;= 0) { currentPage--; [self setThumbnailsForPage:currentPage]; } } #pragma mark - #pragma mark memory management - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; [images release]; } - (void)viewDidUnload { [super viewDidUnload]; [imageViews release]; [fullScreenImage release]; } - (void)dealloc { [images release]; [imageViews release]; [fullScreenImage release]; [super dealloc]; } @end </code></pre> <h2>The result:</h2> <p><img src="https://i.stack.imgur.com/9XD8j.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload