#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. /var/adm/wtmp文件太大该怎么办?

    /var/admin/wtmp文件记录所有用户的登陆信息,随着时间会增长到很大,/var/adm/wtmp文件太大该怎么办呢?先来看看/var/adm/wtmp文件的属性:testterm1:/#ls ...

  2. JavaScript实现文章复制加版权信息

    function addLink() { var body_element = document.getElementsByTagName('body')[0]; var selection; if( ...

  3. Shell check IP

    #! /bin/bash checkip() {        if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3 ...

  4. AOE网络——求关键路径

    1.计算每个活动的最早发生时间(正序) earliest[1]=0; earlest[k]=max{earliest[j],+dut[j][k]} 2.计算每个活动的最晚发生时间(逆序) lastes ...

  5. linux内核图形配置疑难解决

    配置linux内核是遇到的问题:(1)问题一make gconfig * * Unable to find the GTK+ installation. Please make sure that * ...

  6. 洛谷【AT2827】LIS

    浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/A ...

  7. 相当有用的react+redux渲染性能优化原理

    学习地址:http://foio.github.io/react-redux-performance-boost/

  8. 蓝桥杯 历届试题 PREV-32 分糖果

    历届试题 分糖果   时间限制:1.0s   内存限制:256.0MB 问题描述 有n个小朋友围坐成一圈.老师给每个小朋友随机发偶数个糖果,然后进行下面的游戏: 每个小朋友都把自己的糖果分一半给左手边 ...

  9. java流类练习前篇

    总结: package com.aini; import java.io.*; public class gf { public static String main(String[] args) t ...

  10. Mongodb 副本集的节点详细操作

    副本集操作 官方文档:https://docs.mongodb.com/v3.2/reference/method/js-replication/ 1 rs.add(){ _id: <int&g ...