zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

[IOS]图片的旋转和缩放

ios 图片 旋转 缩放
2023-09-27 14:29:23 时间
实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现? 运行的时候按住alt键能够实现图片的伸缩 ViewController.
实现图片的旋转和缩放也是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!