UIScrollView 实现比例缩放
2024-09-21 18:17:48
#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
最新文章
- BizTalk动手实验(十七)ODBC适配器使用
- 有史来最大改变 Android 5.0十大新特性
- Apache的Order Allow,Deny 详解
- C#==>;匿名方法 【转】
- float label 提示
- Case swapping
- 你所不知道的C++
- Java 8 新特性终极版
- Windows 10 IoT Serials 5 - 如何为树莓派应用程序添加语音识别与交互功能
- Linux成为云计算平台的主流操作系统
- ipone 5s上,字体rem遇到的问题
- SpringMVC默认欢迎页面的问题
- SQLite之C#连接SQLite
- mycat->;oracle报java.sql.SQLException: 无法从套接字读取更多的数据
- js javascript 原型链详解
- SpringCloud之自动化配置-config
- 观察者模式——Java实例
- Django使用普通表单、Form、以及modelForm操作数据库方式总结
- 机器学习(四)—逻辑回归LR
- Android ListView 设置
热门文章
- vs2010 oraclelient 引用问题
- winform中的状态栏,以及在状态栏目上显示时间
- python 生成唯一字符串UUID与MD5
- HihoCoder1080 更为复杂的买卖房屋姿势(线段树+多重lazy)
- 2017-2018-1 20179215《Linux内核原理与分析》第十周作业
- 洛谷 P2290 [HNOI2004]树的计数
- vue切换样式
- 爬虫利器 Puppeteer
- jenkins 参数化构建和增加环境变量
- C# Chat曲线图,在发布之后出现错误 Invalid temp directory in chart handler configuration c:\TempImageFiles\