Implement sliding
1. Assign a value to ScrollView's Contentsize property in Viewdidload to tell him the sliding range.
Implementing scaling
1. Set the zoom range in the Attribute tab of the storyboard ScrollView.
2. Implement a Uiscrollviewdelegate[scrollview delegate] and pass it to the ScrollView in Viewdidload
3. Implement uiscrollviewdelegate need to make a carbon copy-(UIView *) Viewforzoominginscrollview: (uiscrollview *) ScrollView
This method returns the view that needs zoom.
Note: If you use zoom and zoom view larger than the screen
You must set the Fram of the view that you want to zoom otherwise the zoom process will change the frame of the view to change to the size of the image causing the ScrollView contentsize change to affect the sliding effect.
So each time you use zoom you need to change the view to set its Frame.szie with its content size binding [like ImageView's image.size]
Brief code:
OC Code
- //
- Isviewcontroller.m
- Imageinscrollview
- //
- Created by Liu Poolo on 12-10-12.
- Copyright (c) 2012 Liu Poolo. All rights reserved.
- //
- #import "ISViewController.h"
- @interface Isviewcontroller () <UIScrollViewDelegate>
- @end
- @implementation Isviewcontroller
- @synthesize Scrollview=_scrollview;
- @synthesize Imageview=_imageview;
- -(void) viewdidload
- {
- [Super Viewdidload];
- Set Uiscrollviewdelegate
- self.scrollview.delegate=self;
- Self.scrollview.contentsize=self.imageview.image.size;
- Self.imageview.frame=cgrectmake (0, 0, Self.imageView.image.size.width, self.imageView.image.size.height);
- Self.imageview.frame=cgrectmake (0, 0, Self.imageView.image.size.width, self.imageView.image.size.height);
- If I don't add this sentence,
- Then normal drag is OK, but if zoom is a problem
- Zoom will change frame to the current display size [imageview default size screen size as full screen is full screen size] Zoom change causes frame synchronization to alter the size of the image to frame size
- The size of the image changes to cause the self.scrollView.contentSize to become a frame and the contentsize becomes smaller and cannot be dragged properly.
- Then change according to zoom zoom scale. Instead of depending on the actual picture size. This causes zoom to be unable to drag [because frame size]
- }
- -(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView
- Returns the view that needs zoom
- {
- If you want ScrollView to implement scaling, you need to give Scrollview.delegate a Uiscrollviewdelegate object
- And this object needs to overwrite the Viewforzoominginscrollview method.
- Summary: Only ScrollView delegate carbon Viewforzoominginscrollview ScrollView will be scaled.
- return self.imageview;
- }
- -(void) didreceivememorywarning
- {
- [Super didreceivememorywarning];
- Self.scrollview=nil;
- Self.imageview=nil;
- }
- @end
[Ios]scrollview for Mobile and zoom