UIGestureRecognizer手勢操作,uigesturerecognizer

來源:互聯網
上載者:User

UIGestureRecognizer手勢操作,uigesturerecognizer

UIGestureRecognizer類,用來檢測,識別使用者使用裝置時所用的手勢,定義了所有手勢的基本行為.以下是UIGestureRecognizer子類,喲關於處理具體的使用者手勢行為。

單擊手勢

單擊手勢UITapGestureRecognizerUITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];    [self.view addGestureRecognizer:singleTap];//單擊事件-(void)singleTap:(UITapGestureRecognizer *)tapgestrue{    NSLog(@"單擊");}


雙擊手勢

UITapGestureRecognizerUITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];    doubleTap.numberOfTapsRequired=2;    [self.view addGestureRecognizer:doubleTap];    //區別單擊雙擊手勢    [singleTap requireGestureRecognizerToFail:doubleTap];//雙擊點擊事件-(void)doubleTap:(UITapGestureRecognizer *)taggestrue{    NSLog(@"雙擊");}

撥動手勢

UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];    //設定輕掃方向,預設向右    swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;    [self.view addGestureRecognizer:swipeGesture];//輕掃事件-(void)swipe:(UISwipeGestureRecognizer *)swipeGesture{    NSLog(@"撥動手勢");}

//平移

UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];    [self.view addGestureRecognizer:panGesture];   //平移事件-(void)pan:(UIPanGestureRecognizer *)pan{    CGPoint point=[pan locationInView:self.view];    NSLog(@"%@",NSStringFromCGPoint(point));}

//長按手勢

 UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];    longPressGesture.minimumPressDuration=2;    [self.view addGestureRecognizer:longPressGesture];//長按手勢事件-(void)longPress:(UILongPressGestureRecognizer *)longPress{    //長按離開時一會調用一次,所以需要設定手勢狀態    if(longPress.state==UIGestureRecognizerStateEnded)    {        return;    }    NSLog(@"長按超過兩秒");}    

//旋轉手勢

UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];    [self.view addGestureRecognizer:rotation];//旋轉事件-(void)rotation:(UIRotationGestureRecognizer *)rotation{    //根據旋轉的弧度獲得角度    float degree=rotation.rotation*(180/M_PI);    NSLog(@"%f",degree);}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.