标签:
1.添加图片 22 //有两种方式 23 //(1)一般方式 24 // 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); 28 29 //(2)使用构造方法 30 UIImage *image=[UIImage imageNamed:@"minion"]; 31 _imageview=[[UIImageView alloc]initWithImage:image]; 32 //调用initWithImage:方法,它创建出来的imageview的宽高和图片的宽高一样
2.手势缩放(scrollView)
(1).设置UIScrollView的id<UISCrollViewDelegate> delegate代理对象
(2).设置minimumZoomScale :缩小的最小比例
(3).设置maximumZoomScale :放大的最大比例
(4).让代理对象实现下面的方法,返回需要缩放的视图控件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
跟缩放相关的常用方法还有
正在缩放的时候调用
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
缩放完毕的时候调用
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
代码实现:
- (void)viewDidLoad {
[super viewDidLoad];
//添加ScrollView
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
//创建imageView
UIImage *image = [UIImage imageNamed:@"big.jpg"];
//调用initWithImage:方法,它创建出来的imageview的宽高和图片的宽高一样
_imageView = [[UIImageView alloc]initWithImage:image];
[scrollView addSubview:_imageView];
//设置滚动的范围
scrollView.contentSize = image.size;
//设置代理:当前的控制器成为scrollView的代理,可以使用scrollView的属性和方法
//按理应该调用[scrollView viewForZoomingInScrollView:scrollView]通知缩放图片,
//现在self就是控制器自己充当了scrollview的代理,直接调用下面的viewForZooming的方法
scrollView.delegate = self;
scrollView.maximumZoomScale = 5.0;
scrollView.minimumZoomScale = 1.0;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _imageView;
}
标签:
原文地址:http://www.cnblogs.com/yuyu-2012/p/4782098.html