yjviewcontroller.m//07-scrollview-View large image////Created by Jacky-mac on 15-6-17.//Copyright (c) 2015 www.train.com. All rights reserved.//#import "YJViewController.h" @interface Yjviewcontroller () <uiscrollviewdelegate>@ Property (Strong, Nonatomic) Iboutlet Uiscrollview *scrollview; @property (nonatomic,strong) Uiimageview *imageview;// Assume that the image is a @property (nonatomic,strong) UIImage *image obtained from the network, @end @implementation yjviewcontroller//image setter-(void) SetImage: (UIImage *) image{_image = image; Sets the contents of the image view Self.imageView.image = image; Let the image view automatically resize according to the image [Self.imageview SizeToFit]; Tell ScrollView the actual size of internal content self.scrollView.contentSize = Image.size;} -(Uiimageview *) imageview{if (_imageview ==nil) {_imageview = [[Uiimageview alloc] init]; [Self.scrollview Addsubview:_imageview]; } return _imageview;} -(Uiscrollview *) scrollview{if (_scrollview = = nil) {_scrollview = [[Uiscrollview alloc] Initwithframe:self.v iew.bOunds]; Set properties//set margin Self.scrollView.contentInset = Uiedgeinsetsmake (20, 20, 20, 20); Do not display horizontal scrolling indicator self.scrollView.showsHorizontalScrollIndicator = no; Do not display vertical scrolling indicator self.scrollView.showsVerticalScrollIndicator = no; Offset position self.scrollView.contentOffset = cgpointmake (0,-100); Cancels the spring effect, the content is fixed, does not want to appear the spring effect when//does not mix with the bounds attribute self.scrollView.bounces = no; Set proxy _scrollview.delegate = self; Set maximum/minimum scaling _scrollview.maximumzoomscale = 2.0; _scrollview.minimumzoomscale = 0.2; [Self.view Addsubview:_scrollview]; } return _scrollview;} -(void) viewdidload{[Super Viewdidload]; Set Image self.image = [UIImage imagenamed:@ "Minion"];} The proxy method for the #pragma mark-uiscrollview/** 1> Sets the proxy 2> specifies the maximum, minimum scale representation that ScrollView is the "return value" of the proxy method that can be scaled is actually the controller tells the scrolling view that the UI is scaled ImageView *///told SCRollview to zoom the view is who, the specific scaling implementation, is done by the ScrollView//1> ScrollView to know to zoom who-(UIView *) Viewforzoominginscrollview: ( Uiscrollview *) scrollview{return self.imageview;} @end
iOS Learning-ScrollView (Image Viewer)