#import "RootViewController.h"

 @interface RootViewController ()<UIScrollViewDelegate>
{
UIImageView *imageView;
UILabel *scaleRatioLabel;// 显示倍率用的Label
}
@property (nonatomic, strong)UIScrollView *scrollView; @end @implementation RootViewController - (void)dealloc
{
self.scrollView = nil;
} - (void)viewDidLoad {
[super viewDidLoad];
self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.scrollView.delegate = self;
[self.view addSubview:self.scrollView];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1-3.jpg"]];
[imageView setCenter:CGPointMake([UIScreen mainScreen].bounds.size.width/2.0, [UIScreen mainScreen].bounds.size.height/2.0)];
[self.scrollView addSubview:imageView];
//内容大小与图片大小一致
self.scrollView.contentSize = imageView.frame.size;
// 最小缩放比例
self.scrollView.minimumZoomScale = 0.2f;
// 最大缩放比例
self.scrollView.maximumZoomScale = 5.0f; // 用来显示倍率的Label
scaleRatioLabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2.0 - , [UIScreen mainScreen].bounds.size.height/2.0 - 12.5, , )];
[scaleRatioLabel setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:scaleRatioLabel]; } #pragma mark - UIScrollViewDelegate
// 设置要缩放的控件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
} // 处理结束缩放事件
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
[self.view bringSubviewToFront:scaleRatioLabel];
[scaleRatioLabel setAlpha:0.6f];
[scaleRatioLabel setBackgroundColor:[UIColor lightGrayColor]];
scaleRatioLabel.text = [NSString stringWithFormat:@" x%.1f",scale]; [UIView transitionWithView:scaleRatioLabel duration:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
scaleRatioLabel.alpha = 0.0f;
} completion:nil];
} @end

最新文章

  1. BizTalk动手实验(十七)ODBC适配器使用
  2. 有史来最大改变 Android 5.0十大新特性
  3. Apache的Order Allow,Deny 详解
  4. C#==&gt;匿名方法 【转】
  5. float label 提示
  6. Case swapping
  7. 你所不知道的C++
  8. Java 8 新特性终极版
  9. Windows 10 IoT Serials 5 - 如何为树莓派应用程序添加语音识别与交互功能
  10. Linux成为云计算平台的主流操作系统
  11. ipone 5s上,字体rem遇到的问题
  12. SpringMVC默认欢迎页面的问题
  13. SQLite之C#连接SQLite
  14. mycat-&gt;oracle报java.sql.SQLException: 无法从套接字读取更多的数据
  15. js javascript 原型链详解
  16. SpringCloud之自动化配置-config
  17. 观察者模式——Java实例
  18. Django使用普通表单、Form、以及modelForm操作数据库方式总结
  19. 机器学习(四)—逻辑回归LR
  20. Android ListView 设置

热门文章

  1. vs2010 oraclelient 引用问题
  2. winform中的状态栏,以及在状态栏目上显示时间
  3. python 生成唯一字符串UUID与MD5
  4. HihoCoder1080 更为复杂的买卖房屋姿势(线段树+多重lazy)
  5. 2017-2018-1 20179215《Linux内核原理与分析》第十周作业
  6. 洛谷 P2290 [HNOI2004]树的计数
  7. vue切换样式
  8. 爬虫利器 Puppeteer
  9. jenkins 参数化构建和增加环境变量
  10. C# Chat曲线图,在发布之后出现错误 Invalid temp directory in chart handler configuration c:\TempImageFiles\