UIScrollView 实现比例缩放
- #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 实现比例缩放的更多相关文章
- UIScrollView 之图片缩放
UIScrollView 之图片缩放 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对其内容进行缩放处理 也就是说,要完成缩放功能的话,只 ...
- C#图片按比例缩放
C#图片按比例缩放: // 按比例缩放图片 public Image ZoomPicture(Image SourceImage, int TargetWidth, int TargetHeight) ...
- html img图片等比例缩放
在img标签里面只设置宽,不设置高,图片就会等比例缩放.
- Java控制图片按比例缩放- (注意内存释放)
package mytiny.com.common; import java.awt.Color;import java.awt.Graphics2D;import java.awt.Image;im ...
- 理解CSS3中的background-size(对响应性图片等比例缩放)
理解CSS3中的background-size(对响应性图片等比例缩放) 阅读目录 background-size的基本属性 给图片设置固定的宽度和高度的 固定宽度400px和高度200px-使用ba ...
- jQuery实现等比例缩放大图片
在布局页面时,有时会遇到大图片将页面容器“撑破”的情况,尤其是加载外链图片(通常是通过采集的外站的图片).那么本文将为您讲述使用jQuery如何按比例缩放大图片,让大图片自适应页面布局. 通常我们 ...
- [原创]C#按比例缩放窗体控件及字体
按照比例缩放窗体控件及字体,如需等比例缩放,只需将x,y的比例设置成相同即可. 为了减小误差,建议使用原始尺寸来计算比例. private float X, Y; private bool b = f ...
- CSS实现图片快速等比例缩放,效果佳
初学者在实现图片等比例缩放,通常会使用js编写逻辑来控制高或宽,达到自动缩放的效果. 这里提供一种纯CSS的图片缩放功能,请看代码: <style type="text/css&quo ...
- 实现web页面按比例缩放
对于web的掌握限于可以看懂别人的代码,并在框架中作相应修改或增加. 今天把另一个项目中的网页源代码粘过来做一个页面,结果问题百出. 首先,同样的代码,放在自己的项目里,页面排版错乱,看了下,引用的w ...
随机推荐
- js修改隔行tr的颜色。
<!DOCTYPE html><html lang="zh-Hans"><head> <meta charset="UTF-8& ...
- c++primer 第三章编程练习答案
3.7.1 #include<iostream> int main() { using namespace std; ; int height,inch,foot; cout <&l ...
- Linux-监控与安全运维之Nagios
1. Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看 ...
- metaclass 了解一下
创建类的两种方式 方式一: class Foo(object,metaclass=type): CITY = "bj" def func(self,x): return x + 1 ...
- Mybatis中对于标签的配置可能不会出现自动提示解决方案
解决办法:引入mybatis-3-config.dtd 文件 Window-preferences-搜索xml-xml catalog <!DOCTYPE configuration PUBLI ...
- 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 ...
- Spring Boot Starter 速查
Spring Boot应用启动器基本的一共有40多种,常用的如下 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring ...
- ajax 原理
Ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用javascript来操作DOM而更新页面. 其中最关键的一步就是从服务器获得请求数据. ...
- java代码I/O类
总结:流类无法理解啊—————— package com.aini; import java.io.*; //流类 //使用FileInputStream读取文件信息 public class ffg ...
- HDFS之三:hdfs参数配置详解
1.hdfs-site.xml 参数配置 – dfs.name.dir – NameNode 元数据存放位置 – 默认值:使用core-site.xml中的hadoop.tmp.dir/dfs/nam ...