中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

UITouch觸摸與手勢

發布時間:2020-09-21 02:36:20 來源:網絡 閱讀:467 作者:jna_114 欄目:開發技術

UITouch觸摸與手勢

1. //延遲調用單擊事件,以便雙擊時可取消單擊調用

        [selfperformSelector:@selector(singleTap) withObject:nilafterDelay:0.2];

2. //類方法取消單擊調用方法,及時調用雙擊方法

        [NSObjectcancelPreviousPerformRequestsWithTarget:selfselector:@selector(singleTap) object:nil];

3.self.clipsToBounds= YES//當子視圖越界時,剪切子視圖

幾種常用的手勢

//創建手勢視圖

    UIView *gestureView = [[UIViewalloc]initWithFrame:CGRectMake(10, 20, 300, 300)];

    gestureView.backgroundColor = [UIColororangeColor];

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(100, 400, 100, 50)];

    label.text = @"0";

    label.textAlignment = NSTextAlignmentCenter;

    label.backgroundColor = [UIColorblueColor];

    label.tag = 100;

    [self.viewaddSubview:label];

    [self.viewaddSubview:gestureView];

   

   

    /******************點擊手勢*******************/

    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap1Action:)];

    //點擊的數量---點擊的次數

    tap1.numberOfTapsRequired = 1;

    //點擊的個數-----手指的個數

    tap1.numberOfTouchesRequired = 1;

    [gestureView  addGestureRecognizer:tap1];

   

    //單手雙擊

UITapGestureRecognizer *tap2 = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap2Action:)];

    tap2.numberOfTouchesRequired = 2;//雙手雙擊

    tap2.numberOfTapsRequired = 2;

    [gestureView addGestureRecognizer:tap2];

    //如果tap2觸發了.tap1則失效-----雙擊時,單擊失效

    [tap1 requireGestureRecognizerToFail:tap2];

   

    /******************輕掃手勢***********************/

    UISwipeGestureRecognizer *swip1 = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swip1Action:)];

    [gestureView addGestureRecognizer:swip1];

   

    /******************平移手勢***********************/

    UIPanGestureRecognizer *pan1 = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(pan1Action:)];

    [gestureView addGestureRecognizer:pan1];

   

    /******************長按手勢***********************/

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPressAction:)];

    [gestureView addGestureRecognizer:longPress];

   

    /******************旋轉手勢***********************/

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotationAction:)];

    [gestureView addGestureRecognizer:rotation];

   

    /******************捏合手勢***********************/

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinchAction:)];

    [gestureView addGestureRecognizer:pinch];

 

 

   

   

}

/******************點擊手勢*******************/

//單擊

- (void)tap1Action:(UITapGestureRecognizer *)tap1

{

    NSLog(@"單擊");

    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    label.text = @"單擊";

}

//雙擊

- (void)tap2Action:(UITapGestureRecognizer *)tap2

{

    NSLog(@"雙擊");

    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    label.text = @"雙擊";

}

/******************輕掃手勢***********************/

- (void)swip1Action:(UISwipeGestureRecognizer *)swip1

{

//    NSLog(@"輕掃");

    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    if (swip1.direction == UISwipeGestureRecognizerDirectionRight) {

        label.text = @"向右輕掃";

    }elseif (swip1.direction == UISwipeGestureRecognizerDirectionLeft){

        label.text = @"向左輕掃";

    }elseif (swip1.direction == UISwipeGestureRecognizerDirectionUp){

        label.text = @"向上輕掃";

    }elseif (swip1.direction == UISwipeGestureRecognizerDirectionDown){

        label.text = @"向下輕掃";

    }

}

/******************平移手勢***********************/

- (void)pan1Action:(UIPanGestureRecognizer *)pan1

{

//    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    CGPoint p1 = [pan1 locationInView:pan1.view];

    NSLog(@"平移的坐標是:%@",NSStringFromCGPoint(p1));

}

/******************長按手勢***********************/

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress

{

    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    if (longPress.state == UIGestureRecognizerStateBegan) {

        label.text = @"開始長按";

    }elseif (longPress.state == UIGestureRecognizerStateEnded){

        label.text = @"長按結束";

    }

   

}

/******************旋轉手勢***********************/

- (void)rotationAction:(UIRotationGestureRecognizer *)rota

{

//    UILabel *label = (UILabel *)[self.viewviewWithTag:100];

    //旋轉的弧度

    CGFloat r = rota.rotation;

    NSLog(@"旋轉的弧度是:%.2f",r);

    NSLog(@"旋轉的角度是:%.2f",180 * r / M_PI);

   

}

/******************捏合手勢***********************/

- (void)pinchAction:(UIPinchGestureRecognizer *)pinch

 

{

    //獲得捏合的比例

    CGFloat scale = pinch.scale;

    pinch.view.transform = CGAffineTransformMakeScale(scale, scale);

}

 


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

奉贤区| 遂溪县| 永寿县| 阿勒泰市| 通山县| 宁强县| 中方县| 东乌珠穆沁旗| 乐业县| 扎赉特旗| 汉阴县| 泗洪县| 米林县| 久治县| 隆尧县| 永清县| 江陵县| 拉萨市| 竹北市| 融水| 朝阳县| 和林格尔县| 兰西县| 曲沃县| 灯塔市| 潼关县| 无棣县| 新乡市| 绥滨县| 德惠市| 石嘴山市| 成安县| 梨树县| 清原| 清丰县| 中牟县| 大厂| 略阳县| 湖口县| 沙雅县| 青海省|