#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIGestureRecognizerDelegate> { float scale; float prviousScale; //放大倍數(shù) float rotation; float previousRotation; //旋轉(zhuǎn)角度 } @property (retain, nonatomic) IBOutlet UIImageView *otherImage; @end
#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]; //旋轉(zhuǎn)事件 UIRotationGestureRecognizer *rotaion=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(doRotate:)]; rotaion.delegate =self; [self.otherImage addGestureRecognizer:rotaion]; //添加自定義手勢(點(diǎn)擊到X大于200的地方相應(yīng)) MyGestureRecongnizer *my = [[MyGestureRecongnizer alloc] initWithTarget:self action:@selector(fun:)]; [self.view addGestureRecognizer:my]; } //自定義手勢觸發(fā)事件 -(void)fun:(MyGestureRecongnizer *)my { NSLog(@"OK"); } //允許同時(shí)調(diào)用兩個(gè)手勢,如果是no的話就只能調(diào)用一個(gè)手勢 -(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; //縮放倍數(shù) [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { prviousScale=scale*prviousScale; scale=1; } } //旋轉(zhuǎn)方法 -(void)doRotate:(UIRotationGestureRecognizer *)gesture { rotation=gesture.rotation; //旋轉(zhuǎn)角度 [self transfromImageView]; if (gesture.state==UIGestureRecognizerStateEnded) { previousRotation=rotation+previousRotation; rotation=0; } } - (void)dealloc { [_otherImage release]; [super dealloc]; } @end
新聞名稱:[IOS]圖片的旋轉(zhuǎn)和縮放
文章鏈接:http://jinyejixie.com/article10/pocjdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、Google、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、做網(wǎng)站、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)