标签:
1 // ViewController.m 2 // 03查看大图 3 // 4 // Created by Administrator on 15/10/10. 5 // Copyright 2015年 ccsu. All rights reserved. 6 // 7 8 #import "ViewController.h" 9 10 @interface ViewController () 11 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 12 @property(nonatomic,strong)UIImageView *imageView; 13 @property(nonatomic,strong)UIImage *image; 14 15 @end 16 17 @implementation ViewController 18 19 -(void)setImage:(UIImage *)image{ 20 _image = image; 21 //设置图像内容 22 self.imageView.image = image;//把图像传给UIImageView 23 //让图像视图根据图像自动调整大小 24 [self.imageView sizeToFit]; 25 //告诉ScrollView内部内容大小 26 self.scrollView.contentSize = image.size; 27 28 29 30 } 31 -(UIImageView *)imageView{ 32 if (_imageView == nil) { 33 _imageView = [[UIImageView alloc]init]; 34 [self.scrollView addSubview:_imageView]; 35 } 36 return _imageView; 37 38 } 39 - (void)viewDidLoad { 40 [super viewDidLoad]; 41 42 self.image = [UIImage imageNamed:@"minion"]; 43 //设置边距 44 self.scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20); 45 //不显示水平滚动标识(滚动条) 46 self.scrollView.showsHorizontalScrollIndicator = NO; 47 //不显示垂直滚动标识 48 self.scrollView.showsVerticalScrollIndicator = NO; 49 //偏移位置 50 self.scrollView.contentOffset = CGPointMake(100, 100); 51 //弹簧效果,取消就是NO 52 self.scrollView.bounces = YES; 53 UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd]; 54 btn.center = self.view.center; 55 [self.view addSubview:btn]; 56 57 [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; 58 59 } 60 61 -(void)click 62 { 63 64 //移动大图的偏移位置.结构体只能不能直接赋值; 65 CGPoint offset = self.scrollView.contentOffset; 66 offset.x += 20; 67 offset.y += 20; 68 //注意:设置contentoffset 会忽略contentSize(即scrollview得总大小) 69 self.scrollView.contentOffset = offset; 70 71 72 } 73 74 @end
标签:
原文地址:http://www.cnblogs.com/Simplelee/p/4887604.html