In this section, we implement the ability to enlarge the image by clicking on the image.
First we create a class named Flickrphotoviewconroller, which inherits from Uiviewcontroller.
Change header file contents such as the following:
#import <UIKit/UIKit.h> @class Flickrphoto; @interface Flickrphotoviewconroller:uiviewcontroller@property ( Nonatomic, strong) Flickrphoto *flickrphoto; @end
Declaring outlet and action:
#import "FlickrPhotoViewConroller.h" #import "Flickr.h" #import "FlickrPhoto.h" @interface Flickrphotoviewconroller () @property (weak) Iboutlet Uiimageview *imageview;-(ibaction) Done: (ID) sender; @end
Open Storyboard, add a Uiviewcontroller to storyboard, set the view class to Flickrphotoviewconroller.
Use Ctrl+drag from the main view to create a modal segue to the Flickr Photo view Controller.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvewftaw5nd3u=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
Select this segue. Set its identifier to Showflickrphoto
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvewftaw5nd3u=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
Add a toolbar and a imageview to the view, and change the ToolBarButton title to the Done,ctrl+drag connection button and Flickrphotoviewcontroller done: method.
And then connect the ImageView outlet:
Open VIEWCONTROLLER.M. Add the following code to the @interface area:
@property (nonatomic) BOOL sharing;
To change the Didselectitematindexpath method:
if (!self.sharing) { NSString *searchterm = self.searchs[indexpath.section]; Flickrphoto *photo = Self.searchresults[searchterm][indexpath.row]; [Self performseguewithidentifier:@ "Showflickrphoto" Sender:photo]; [Self.collectionview Deselectitematindexpath:indexpath animated:yes]; } else { }
When the user clicks on a thumbnail, it runs Showflickrphoto segue.
#import "FlickrPhotoViewConroller.h"-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{ if ( [Segue.identifier isequaltostring:@ "Showflickrphoto"]) { Flickrphotoviewconroller *flickrphotoviewcontroller = Segue.destinationviewcontroller; Flickrphotoviewcontroller.flickrphoto = sender; }}
Implement the Viewwillappear method. Show large picture to view:
-(void) Viewdidappear: (BOOL) Animated {//1 if (self.flickrPhoto.largeImage) { self.imageView.image = self.flickrPhoto.largeImage; } else {//2 self.imageView.image = Self.flickrPhoto.thumbnail; 3 [Flickr loadImageForPhoto:self.flickrPhoto thumbnail:no completionblock:^ (UIImage *photoimage, Nserror * Error) { if (!error) {//4 Dispatch_async (Dispatch_get_main_queue (), ^{self.imageView.image = Self.flickrPhoto.largeImage;} );}} ];} }
Implement the Done method. Return to main view by clicking Donebutton:
-(void) Done: (ID) sender{ [Self.presentingviewcontroller dismissviewcontrolleranimated:yes completion:^{}];}
The program works like the following:
IOS Uicollectionview Get started 07 Click cell to enlarge image