[IOS]图片的旋转和缩放

实现图片的旋转和缩放也是IOS开发中一个比较常见的技术点,下面我们来一起学习,这功能如何实现?

效果图:

[IOS]图片的旋转和缩放
运行的时候按住alt键能够实现图片的伸缩

ViewController.h:

#import   @interface ViewController : UIViewController  {     float scale;     float prviousScale;  //放大倍数     float rotation;     float previousRotation; //旋转角度 } @property (retain, nonatomic) IBOutlet UIImageView *otherImage;  @end 

ViewController.m:

#import "ViewController.h" #import "MyGestureRecongnizer.h"  //自定义手势 @interface ViewController ()  @end  @implementation ViewController  - (void)viewDidLoad {     [super viewDidLoad];     prviousScale=1; 	     //缩放手势     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];           } //自定义手势触发事件 -(void)fun:(MyGestureRecongnizer *)my {     NSLog(@"OK"); }  //允许同时调用两个手势,如果是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;     } }   - (void)dealloc {     [_otherImage release];     [super dealloc]; } @end 




网站标题:[IOS]图片的旋转和缩放
本文来源:http://bzwzjz.com/article/pocjdo.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 响应式网站设计 网站制作报价 商城网站建设 成都网站建设 成都响应式网站建设 温江网站设计 成都网站制作 成都网站建设 定制网站设计 手机网站建设套餐 成都网站建设公司 H5网站制作 手机网站设计 成都网站建设公司 成都响应式网站建设公司 重庆网站建设 成都商城网站建设 营销型网站建设 宜宾网站设计 手机网站制作 公司网站建设 定制网站建设