| •cgsize contentsize: |
Set the scroll range for Uiscrollview |
| •cgpoint Contentoffset: |
Uiscrollview the current scrolling position |
| •uiedgeinsets Contentinset: |
Increase scrolling range around the scrolling view |
1. Create
Uiscrollview *scrollview = [[Uiscrollview alloc]initwithframe:self.view.bounds]; [Self.view Addsubview:scrollview];
2. Add ImageView
UIImage *image = [UIImage imagenamed:@ "001.jpeg"]; *imageview = [[Uiimageview alloc]initwithimage:image]; [ScrollView Addsubview:imageview]; // If you do not specify a uiimageview size, the size of the image is used by default
3. Set scrolling properties
// 2. Set scrolling View Properties [ScrollView setContentSize:image.size];
4. Set boundary properties
// set boundary Properties Uiedgeinsets EDGs = Uiedgeinsetsmake (ten); // Top left down right [ScrollView Setcontentinset:edgs];
5. Set whether you have spring properties
[_scrollview Setbounces:no];
6. Setting the horizontal scroll bar
[_scrollview Setshowshorizontalscrollindicator:no]; [_scrollview Setshowsverticalscrollindicator:no];
7. Set zoom in and zoom out
// Specify the minimum zoom ratio [_scrollview Setminimumzoomscale:0.2]; // Specify the maximum zoom ratio [_scrollview Setmaximumzoomscale:2.0]; // to set the proxy for a scrolling view [_scrollview setdelegate:self];
8. How to perform when zooming
#pragma The proxy method for the Mark scrolling view // Scaling Proxy method -(void) Scrollviewdidzoom: (Uiscrollview *) scrollview{ NSLog (@ " zooming in ... ");}
9. Scaling to complete the execution of the agent method
//Proxy method for scaling complete- (void) Scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (float) scale{NSLog (@"Zoom Complete%f", scale); //try a different image .NSString *imagefile = [NSString stringWithFormat:@"%03d.jpeg", Arc4random_uniform (Ten) +1]; UIImage*image =[UIImage Imagenamed:imagefile]; [_imageview setimage:image];}
10. Return the View object to zoom
// Be sure to remember that the return value of this proxy method is the "View object to be scaled"-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) scrollview{ return _imageview;}
11. How to move Images
-(Ibaction) Moveimage: (UIButton *) sender{cgpoint offset=_scrollview.contentoffset; Switch(Sender.tag) { Case 0: Offset.x-= -; Break; Case 1: Offset.y-= -; Break; Case 2: Offset.y+= -; Break; Case 3: Offset.x+= -; Break; default: Break; } //need to make a correction to the position//Horizontal, note that you need to use the-left of the edge when correcting the left positionUiedgeinsets edge =_scrollview.contentinset; if(Offset.x <-edge.left) {offset.x= -Edge.left; } Else if(Offset.x > _scrollview.contentsize.width-_scrollview.bounds.size.width +edge.right) {offset.x= _scrollview.contentsize.width-_scrollview.bounds.size.width +Edge.right; } //in the vertical direction, note that when correcting the top position, you need to use the Edge's-top if(Offset.y <-edge.top) {Offset.y= -Edge.top; } Else if(Offset.y > _scrollview.contentsize.height-_scrollview.bounds.size.height +edge.bottom) {Offset.y= _scrollview.contentsize.height-_scrollview.bounds.size.height +Edge.bottom; } [_scrollview Setcontentoffset:offset animated:yes];
12. Add Mobile Animations
// Cheap Locations for modifying images [UIView animatewithduration:0.3f animations: ^{ [_scrollview setcontentoffset:o Ffset]; }];
"IOS"-ScrollView-01