[IOS]图片的旋转和缩放
ios 图片 旋转 缩放
2023-09-27 14:29:23 时间
实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现?
运行的时候按住alt键能够实现图片的伸缩
ViewController.
实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现? 运行的时候按住alt键能够实现图片的伸缩 ViewController.h:
ViewController.m:
//缩放手势 UIPinchGestureRecognizer *pin=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(doPinch:)]; pin.delegate=self; [self.otherImage addGestureRecognizer:pin]; //旋转事件 UIRotationGestureRecognizer *rotaion=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(doRotate:)]; rotaion.delegate =self; [self.otherImage addGestureRecognizer:rotaion];
//添加自定义手势(点击到X大于200的地方相应) MyGestureRecongnizer *my = [[MyGestureRecongnizer alloc] initWithTarget:self action:@selector(fun:)]; [self.view addGestureRecognizer:my];
//允许同时调用两个手势,如果是no的话就只能调用一个手势 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer return YES; -(void)transfromImageView CGAffineTransform t=CGAffineTransformMakeScale(scale*prviousScale, scale*prviousScale); t=CGAffineTransformRotate(t, rotation+previousRotation); self.otherImage.transform=t; //缩放方法 -(void)doPinch:(UIPinchGestureRecognizer *)gesture scale=gesture.scale; //缩放倍数 [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { prviousScale=scale*prviousScale; scale=1; //旋转方法 -(void)doRotate:(UIRotationGestureRecognizer *)gesture rotation=gesture.rotation; //旋转角度 [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { previousRotation=rotation+previousRotation; rotation=0;
iOS MachineLearning 系列(16)—— 几个常用的图片分类CoreML模型 对于图片识别分类的模型来说,其输入和输出都一样,输入都为图像参数,输入为两部分,一部分为最佳预测结果,一部分为可能得预测结果及其可信度。
iOS MachineLearning 系列(7)—— 图片相似度分析 图片相似度分析是Vision框架中提供的高级功能。其本质是计算图片的特征值,通过特征值的比较来计算出图片特征差距,从而可以获取到图片的相似程度。在实际应用中,图片的相似度分析有着广泛的应用。如人脸对比识别,相似物品的搜索和识别等。
蓬莱仙羽 麦子学院讲师,游戏蛮牛专栏作家,CSDN博客专家,热爱游戏开发,热爱Coding!
实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现? 运行的时候按住alt键能够实现图片的伸缩 ViewController.h:
#import UIKit/UIKit.h @interface ViewController : UIViewController UIGestureRecognizerDelegate float scale; float prviousScale; //放大倍数 float rotation; float previousRotation; //旋转角度 @property (retain, nonatomic) IBOutlet UIImageView *otherImage;
ViewController.m:
//缩放手势 UIPinchGestureRecognizer *pin=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(doPinch:)]; pin.delegate=self; [self.otherImage addGestureRecognizer:pin]; //旋转事件 UIRotationGestureRecognizer *rotaion=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(doRotate:)]; rotaion.delegate =self; [self.otherImage addGestureRecognizer:rotaion];
//添加自定义手势(点击到X大于200的地方相应) MyGestureRecongnizer *my = [[MyGestureRecongnizer alloc] initWithTarget:self action:@selector(fun:)]; [self.view addGestureRecognizer:my];
//允许同时调用两个手势,如果是no的话就只能调用一个手势 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer return YES; -(void)transfromImageView CGAffineTransform t=CGAffineTransformMakeScale(scale*prviousScale, scale*prviousScale); t=CGAffineTransformRotate(t, rotation+previousRotation); self.otherImage.transform=t; //缩放方法 -(void)doPinch:(UIPinchGestureRecognizer *)gesture scale=gesture.scale; //缩放倍数 [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { prviousScale=scale*prviousScale; scale=1; //旋转方法 -(void)doRotate:(UIRotationGestureRecognizer *)gesture rotation=gesture.rotation; //旋转角度 [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { previousRotation=rotation+previousRotation; rotation=0;
iOS MachineLearning 系列(16)—— 几个常用的图片分类CoreML模型 对于图片识别分类的模型来说,其输入和输出都一样,输入都为图像参数,输入为两部分,一部分为最佳预测结果,一部分为可能得预测结果及其可信度。
iOS MachineLearning 系列(7)—— 图片相似度分析 图片相似度分析是Vision框架中提供的高级功能。其本质是计算图片的特征值,通过特征值的比较来计算出图片特征差距,从而可以获取到图片的相似程度。在实际应用中,图片的相似度分析有着广泛的应用。如人脸对比识别,相似物品的搜索和识别等。
蓬莱仙羽 麦子学院讲师,游戏蛮牛专栏作家,CSDN博客专家,热爱游戏开发,热爱Coding!
相关文章
- iOS微信授权登录添加Universal Link支持
- iOS 图片比例缩放
- iOS摄像头和相册-UIImagePickerController常用操作
- IOS的APNS和PushKit门道详述
- 《iOS 8应用开发入门经典(第6版)》——第2章,第2.4节小结
- 《iOS 6核心开发手册(第4版)》——2.11节秘诀:构建星星滑块
- iOS中拉伸图片的几种方式
- iOS View自定义窍门——UIButton实现上显示图片,下显示文字
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- ios像素点颜色取样
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- iOS应用的启动流程和优化详解
- iOS 线上版本图片资源格式的问题导致的闪退
- [iOS 10 day by day] Day 1:开发 iMessage 的第三方插件
- iOS开发基础知识:Core Animation(核心动画)
- iOS开发需要哪些图片?
- 史上最全的iOS面试题及答案,且看且珍藏,错过就没有喽!
- 《iOS应用软件设计之道》—— 2.2 谈话中论设计
- uniapp踩坑问题记录:iOS微信分享图片不显示安卓分享正常、Do not nest other components in the text component提示问题
- iOS-default.png启动图片
- IOS开源项目指标
- iOS - 长按图片识别图中二维码
- iOS 获取图片的原始格式
- 将app安装到ios模拟器