IOS, Objective-C, and album functions ., Iosobjective-c
# 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) * 4, gao); _ huaKuang. backgroun DColor = [UIColor blackColor]; // set pagination _ huaKuang. pagingEnabled = YES; // hide the scroll bar // whether the horizontal scroll bar _ huaKuang is displayed during scrolling. showsHorizontalScrollIndicator = NO; // whether the vertical scroll bar _ huaKuang is displayed during scrolling. showsVerticalScrollIndicator = NO; // set the proxy, which must follow the proxy protocol <UIScrollViewDelegate> and be written at the end of @ interface ViewController () _ huaKuang. delegate = self; // Add a subview. Because there are multiple subviews, a method is written to add [self tianJianZiShiTu];}-(void) tianJianZiShiTu {// if there are six images, create six uiscrollviews and six UIImag EView, and find the six images for (int I = 0; I <3; I ++) {// create UIScrollView // Add a 20 black edge to separate different photos, set Left in ScrollViewscroll View and Width UIScrollView in View * uisv = [[UIScrollView alloc] initWithFrame: CGRectMake (kuan + 20) * I, 0, kuan, gao)]; // Add the created image to the total UIScrollView [_ huaKuang addSubview: uisv]; // create UIImageView * uiiv = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, kuan, gao)]; // Add the created UIImageView to UIScrollV In iew, [uisv addSubview: uiiv]; // sets the image NSString * imageName = [NSString stringWithFormat: @ "new_feature _ % d", I + 1]; uiiv. image = [UIImage imageNamed: imageName]; // set the tag value uiiv. tag = 1000; // set UIScrollView proxy uisv. delegate = self; // set the zoom range uisv. minimumZoomScale = 0.5; uisv. maximumZoomScale = 1.5; // defines the Click Event UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (d IanJiShiJian :)]; // sets the number of valid clicks (double-click. numberOfTapsRequired = 2; // Add it to UIScrollView [uisv addGestureRecognizer: tap] ;}}-(void) dianJiShiJian :( UITapGestureRecognizer *) tap {// obtain the view UIScrollView * uisv1 = (UIScrollView *) tap of the click event. 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 the scaled view-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView {if (scrollView = _ huaKuang) {return nil;} UIImageView * imageView = (UIImageView *) [scrollView viewWithTag: 1000]; return imageView;} // The scroll ends, set the scaling ratio 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