ios開發手勢處理之手勢識別二

來源:互聯網
上載者:User

標籤:

#import "ViewController.h"@interface ViewController ()<UIGestureRecognizerDelegate>@property (weak, nonatomic) IBOutlet UIImageView *imageV;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.            self.imageV.userInteractionEnabled = YES;         //添加旋轉手勢    [self rotationGes];          //添加捏合手勢    [self pinch];        }//Simultaneous:同時//是否允許同時支援多個手勢-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{    return YES;} //添加旋轉手勢- (void)rotationGes{    //添加旋轉手勢    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGes:)];        rotation.delegate = self;        [self.imageV addGestureRecognizer:rotation];}- (void)rotationGes:(UIRotationGestureRecognizer *)rotationGes{    self.imageV.transform = CGAffineTransformRotate(self.imageV.transform, rotationGes.rotation);        //複位    [rotationGes setRotation:0];        }  //添加捏合手勢- (void)pinch{      UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];    pinch.delegate = self;    [self.imageV addGestureRecognizer:pinch];}//當縮放時調用- (void)pinch:(UIPinchGestureRecognizer *)pinch{    NSLog(@"%s",__func__);    self.imageV.transform = CGAffineTransformScale(self.imageV.transform, pinch.scale,pinch.scale );        //複位    [pinch setScale:1];}- (void)panGes{    //添加拖動手勢    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];    [self.imageV addGestureRecognizer:pan];}//當拖動View時調用- (void)pan:(UIPanGestureRecognizer *)pan {        //擷取位移量(相對於最原始的位移量)    CGPoint transP = [pan translationInView:self.imageV];    NSLog(@"%@",NSStringFromCGPoint(transP));        self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform, transP.x, transP.y);        //讓它相對於上一次    //複位.    [pan setTranslation:CGPointZero inView:self.imageV];    }@end

 

ios開發手勢處理之手勢識別二

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.