1. Add picture //There are two ways// (1) General way// Uiimageview *imageview=[[uiimageview alloc]init];25// UIImage *image=[uiimage imagenamed:@ "Minion"];26// imageview.image=image;27// imageview.frame= CGRectMake (0, 0, image.size.width, image.size.height); (2) using the construction method of UIImage *image=[uiimage imagenamed:@ "Minion"];31 _imageview=[[uiimageview alloc]initwithimage:image];32 //Call InitWithImage: Method, It creates the width of the ImageView and the width of the picture as high as
2. gesture Scaling (ScrollView)
(1). Set id<uiscrollviewdelegate> delegate proxy object for Uiscrollview
(2). Setting Minimumzoomscale: Minimum scale reduction
(3). Setting Maximumzoomscale: Maximum scale magnification
(4). Let the proxy object implement the following method to return the view control that needs to be scaled
-(UIView *)Viewforzoominginscrollview:(Uiscrollview *) ScrollView
The common methods associated with scaling are also
is being scaled when calling the
-(void)Scrollviewdidzoom:(Uiscrollview *) ScrollView
Call when Zoom is complete
-(void)scrollviewdidendzooming:(Uiscrollview *) ScrollView Withview:(UIView *) View Atscale :(float) scale
Code implementation:
-(void) Viewdidload {
[Super Viewdidload];
Add ScrollView
Uiscrollview *scrollview = [[Uiscrollview alloc]initwithframe:self. View. Bounds];
[Self. view Addsubview:scrollview];
Create ImageView
UIImage *image = [UIImage imagenamed:@ "big.jpg"];
Call Initwithimage: method, which creates the width of the ImageView and the width of the picture as high as
_imageview = [[uiimageview alloc]initwithimage:image];
[ScrollView Addsubview:_imageview];
//Set the range of scrolling
ScrollView. contentsize = image. size;
Set Proxy: The current controller becomes a proxy for ScrollView, you can use the properties and methods of ScrollView
You should call the [ScrollView Viewforzoominginscrollview:scrollview] notification to zoom the picture,
now Self is the controller itself acting as the agent of ScrollView , directly call the following viewforzooming method
ScrollView. delegate = self ;
ScrollView. Maximumzoomscale = 5.0;
ScrollView. Minimumzoomscale = 1.0;
}
-(UIView *) Viewforzoominginscrollview: (uiscrollview *) scrollview{
return _imageview;
}
Uiimageview in iOS