ios - How do I make an image expand to full screen when touched? -


i'd make facebook-like ios app, makes picture timeline full screen when user taps on it.

update:

i'm using uicollectionview display image in cell, seems should using collectionview:didselectitematindexpath: method? , imageview in cell, can still expand full screen directly?

attached couple images below:

enter image description here

enter image description here

here's basic solution. assumes collection cell has uiimageview subview of uicollectionviewcell contentview.

#import <objc/runtime.h> // objc_setassociatedobject / objc_getassociatedobject 

...

- (void) collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath {     uicollectionviewcell* cell = [collectionview cellforitematindexpath:indexpath];      uiimageview* iv = cell.contentview.subviews.lastobject;      uiimageview* ivexpand = [[uiimageview alloc] initwithimage: iv.image];     ivexpand.contentmode = iv.contentmode;     ivexpand.frame = [self.view convertrect: iv.frame fromview: iv.superview];     ivexpand.userinteractionenabled = yes;     ivexpand.clipstobounds = yes;      objc_setassociatedobject( ivexpand,                               "original_frame",                               [nsvalue valuewithcgrect: ivexpand.frame],                               objc_association_retain);      [uiview transitionwithview: self.view                       duration: 1.0                        options: uiviewanimationoptionallowanimatedcontent                     animations:^{                          [self.view addsubview: ivexpand];                         ivexpand.frame = self.view.bounds;                      } completion:^(bool finished) {                          uitapgesturerecognizer* tgr = [[uitapgesturerecognizer alloc] initwithtarget: self action: @selector( ontap: )];                         [ivexpand addgesturerecognizer: tgr];                     }]; }  - (void) ontap: (uitapgesturerecognizer*) tgr {     [uiview animatewithduration: 1.0                      animations:^{                           tgr.view.frame = [objc_getassociatedobject( tgr.view,                                                                     "original_frame" ) cgrectvalue];                      } completion:^(bool finished) {                           [tgr.view removefromsuperview];                      }]; } 

Comments