#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

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. hdoj-3791-二叉搜索树(二叉搜索树模板题)

    #include <cstring> #include <cstdio> #include <iostream> using namespace std; type ...

  2. L118

    The company needs to focus on its biggest clients.This article discussed the events that led to her ...

  3. 整理下PC和移动获取点击、移动坐标的代码和坑

    一.PC PC是通过鼠标点击和移动,相对比较简单,比如onmousedown.onmouseup.onmousemove.onmouseout鼠标按键按下.按键起来.鼠标在元素上移动.鼠标从元素上离开 ...

  4. hdu4451 Dressing(容斥原理)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  5. 杂项之python利用pycrypto实现RSA

    杂项之python利用pycrypto实现RSA 本节内容 pycrypto模块简介 RSA的公私钥生成 RSA使用公钥加密数据 RSA使用私钥解密密文 破解博客园登陆 pycrypto模块简介 py ...

  6. 算法之python创建链表实现cache

    算法之python创建链表实现cache 本节内容 问题由来 解决思路 实现代码 总结 1. 问题由来 问题起因于朋友的一次面试题,面试公司直接给出两道题,要求四十八小时之内做出来,语言不限,做出来之 ...

  7. kali_linux学习笔记

    kali linux ssh登陆: 一.配置SSH参数 修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#PasswordAuthentication no ...

  8. java添加背景图片

    总结:我们通常实现添加背景图片很容易,但是再添加按钮组件就会覆盖图片.原因是: 有先后啊.setlayout();与布局有很大关系 请调试代码的时候,仔细揣摩.我晕了 还可以添加文本框,密码框 fra ...

  9. 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)

    链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...

  10. Oracle 存储过程学习笔记

    1.存储过程简单实例 CREATE OR REPLACE PROCEDURE 存储过程名称 (参数in,参数out) AS -- 变量声明,每个声明用分号结束.可以在声明的同时初始化 name ); ...