1. #import "RootViewController.h"
  2.  
  3. @interface RootViewController ()<UIScrollViewDelegate>
  4. {
  5. UIImageView *imageView;
  6. UILabel *scaleRatioLabel;// 显示倍率用的Label
  7. }
  8. @property (nonatomic, strong)UIScrollView *scrollView;
  9.  
  10. @end
  11.  
  12. @implementation RootViewController
  13.  
  14. - (void)dealloc
  15. {
  16. self.scrollView = nil;
  17. }
  18.  
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  22. self.scrollView.delegate = self;
  23. [self.view addSubview:self.scrollView];
  24. imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1-3.jpg"]];
  25. [imageView setCenter:CGPointMake([UIScreen mainScreen].bounds.size.width/2.0, [UIScreen mainScreen].bounds.size.height/2.0)];
  26. [self.scrollView addSubview:imageView];
  27. //内容大小与图片大小一致
  28. self.scrollView.contentSize = imageView.frame.size;
  29. // 最小缩放比例
  30. self.scrollView.minimumZoomScale = 0.2f;
  31. // 最大缩放比例
  32. self.scrollView.maximumZoomScale = 5.0f;
  33.  
  34. // 用来显示倍率的Label
  35. scaleRatioLabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2.0 - , [UIScreen mainScreen].bounds.size.height/2.0 - 12.5, , )];
  36. [scaleRatioLabel setBackgroundColor:[UIColor clearColor]];
  37. [self.view addSubview:scaleRatioLabel];
  38.  
  39. }
  40.  
  41. #pragma mark - UIScrollViewDelegate
  42. // 设置要缩放的控件
  43. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  44. {
  45. return imageView;
  46. }
  47.  
  48. // 处理结束缩放事件
  49. - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
  50. {
  51. [self.view bringSubviewToFront:scaleRatioLabel];
  52. [scaleRatioLabel setAlpha:0.6f];
  53. [scaleRatioLabel setBackgroundColor:[UIColor lightGrayColor]];
  54. scaleRatioLabel.text = [NSString stringWithFormat:@" x%.1f",scale];
  55.  
  56. [UIView transitionWithView:scaleRatioLabel duration:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
  57. scaleRatioLabel.alpha = 0.0f;
  58. } completion:nil];
  59. }
  60.  
  61. @end

UIScrollView 实现比例缩放的更多相关文章

  1. UIScrollView 之图片缩放

    UIScrollView 之图片缩放 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对其内容进行缩放处理 也就是说,要完成缩放功能的话,只 ...

  2. C#图片按比例缩放

    C#图片按比例缩放: // 按比例缩放图片 public Image ZoomPicture(Image SourceImage, int TargetWidth, int TargetHeight) ...

  3. html img图片等比例缩放

    在img标签里面只设置宽,不设置高,图片就会等比例缩放.

  4. Java控制图片按比例缩放- (注意内存释放)

    package mytiny.com.common; import java.awt.Color;import java.awt.Graphics2D;import java.awt.Image;im ...

  5. 理解CSS3中的background-size(对响应性图片等比例缩放)

    理解CSS3中的background-size(对响应性图片等比例缩放) 阅读目录 background-size的基本属性 给图片设置固定的宽度和高度的 固定宽度400px和高度200px-使用ba ...

  6. jQuery实现等比例缩放大图片

      在布局页面时,有时会遇到大图片将页面容器“撑破”的情况,尤其是加载外链图片(通常是通过采集的外站的图片).那么本文将为您讲述使用jQuery如何按比例缩放大图片,让大图片自适应页面布局. 通常我们 ...

  7. [原创]C#按比例缩放窗体控件及字体

    按照比例缩放窗体控件及字体,如需等比例缩放,只需将x,y的比例设置成相同即可. 为了减小误差,建议使用原始尺寸来计算比例. private float X, Y; private bool b = f ...

  8. CSS实现图片快速等比例缩放,效果佳

    初学者在实现图片等比例缩放,通常会使用js编写逻辑来控制高或宽,达到自动缩放的效果. 这里提供一种纯CSS的图片缩放功能,请看代码: <style type="text/css&quo ...

  9. 实现web页面按比例缩放

    对于web的掌握限于可以看懂别人的代码,并在框架中作相应修改或增加. 今天把另一个项目中的网页源代码粘过来做一个页面,结果问题百出. 首先,同样的代码,放在自己的项目里,页面排版错乱,看了下,引用的w ...

随机推荐

  1. js修改隔行tr的颜色。

    <!DOCTYPE html><html lang="zh-Hans"><head> <meta charset="UTF-8& ...

  2. c++primer 第三章编程练习答案

    3.7.1 #include<iostream> int main() { using namespace std; ; int height,inch,foot; cout <&l ...

  3. Linux-监控与安全运维之Nagios

    1. Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看 ...

  4. metaclass 了解一下

    创建类的两种方式 方式一: class Foo(object,metaclass=type): CITY = "bj" def func(self,x): return x + 1 ...

  5. Mybatis中对于标签的配置可能不会出现自动提示解决方案

    解决办法:引入mybatis-3-config.dtd 文件 Window-preferences-搜索xml-xml catalog <!DOCTYPE configuration PUBLI ...

  6. Poj 3287 Catch That Cow(BFS)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  7. Spring Boot Starter 速查

    Spring Boot应用启动器基本的一共有40多种,常用的如下 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring ...

  8. ajax 原理

    Ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用javascript来操作DOM而更新页面.    其中最关键的一步就是从服务器获得请求数据. ...

  9. java代码I/O类

    总结:流类无法理解啊—————— package com.aini; import java.io.*; //流类 //使用FileInputStream读取文件信息 public class ffg ...

  10. HDFS之三:hdfs参数配置详解

    1.hdfs-site.xml 参数配置 – dfs.name.dir – NameNode 元数据存放位置 – 默认值:使用core-site.xml中的hadoop.tmp.dir/dfs/nam ...