#import "ViewController.h" #define Kuan [UIScreen mainscreen].bounds.size.width#define Gao [UIScreen mainscreen]. Bounds.size.height@interface Viewcontroller () <UIScrollViewDelegate> @property (weak, nonatomic) Iboutlet Uiscrollview *huakuang; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Set Contentsize _huakuang.contentsize=cgsizemake ((Kuan), GAO); _huakuang.backgroundcolor=[uicolor Blackcolor]; Set paging _huakuang.pagingenabled=yes; Hide scroll bar//Scroll when the horizontal scroll bar is displayed _huakuang.showshorizontalscrollindicator=no; Whether to display the vertical scroll bar _huakuang.showsverticalscrollindicator=no when scrolling; Set up the agent, need to follow the proxy protocol <uiscrollviewdelegate>, written in @interface Viewcontroller () behind _huakuang.delegate=self; Add a child view because it is multiple so write a method to implement add [self Tianjianzishitu];} -(void) tianjianzishitu{//If there are six images, create six uiscrollview and six Uiimageview, and find six pictures for (int i=0;i<3;i++) {//Create Uiscrollview//In order to distinguish different photos plus a 20 black edge, you need to set the Scrollviewscroll view in the left and the view of WIDTh uiscrollview *uisv=[[uiscrollview alloc] Initwithframe:cgrectmake ((kuan+20) *i, 0, Kuan, Gao)]; Add the creation complete to the total of the Uiscrollview [_huakuang ADDSUBVIEW:UISV]; Create Uiimageview Uiimageview *uiiv=[[uiimageview alloc] Initwithframe:cgrectmake (0, 0, Kuan, Gao)]; Add the created Uiimageview to the Uiscrollview [UISV Addsubview:uiiv]; Set the picture of Uiimageview nsstring *imagename = [NSString stringwithformat:@ "new_feature_%d", i + 1]; Uiiv.image=[uiimage Imagenamed:imagename]; Set tag value uiiv.tag=1000; Set the agent uisv.delegate=self of Uiscrollview; Set the zoom range uisv.minimumzoomscale=0.5; uisv.maximumzoomscale=1.5; Define Click events UITapGestureRecognizer *tap=[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector (Dianjishi Jian:)]; Set the number of effective clicks (that is, double-click) tap.numberoftapsrequired=2; Added to Uiscrollview [UISV Addgesturerecognizer:tap]; }}-(void) Dianjishijian: (uitapgesturereCognizer *) tap{//Get click event for View Uiscrollview *uisv1= (Uiscrollview *) Tap.view; if (uisv1.zoomscale!=1.0) {[Uisv1 setzoomscale:1.0 animated:yes]; return; } cgpoint Location=[tap LocationInView:tap.view]; CGRect Rect=cgrectmake (location.x-100, location.y-100, 200, 200); [Uisv1 zoomtorect:rect animated:yes];} Specify scaled View-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) scrollview{if (ScrollView = = _huakuang) {return Nil } Uiimageview *imageview = (Uiimageview *) [ScrollView viewwithtag:1000]; return ImageView;} Scroll to the end and set the zoom scale of all zoom views to 1.0-(void) scrollviewdidenddecelerating: (Uiscrollview *) scrollview{if (ScrollView = = _ Huakuang) {for (id obj in _huakuang.subviews) {if ([obj Iskindofclass:[uiscrollview class]]) { Uiscrollview *scalesc = (Uiscrollview *) obj; Scalesc.zoomscale = 1.0; }}}}-(void) didreceivememorywarning {[Super didreceivememorywarning];} @end
IOS,OBJECTIVE-C, the realization of the album function.