第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

UITapGestureRecognizer-使它在觸地而不是觸地工作嗎?

UITapGestureRecognizer-使它在觸地而不是觸地工作嗎?

慕碼人2483693 2019-11-27 09:55:26
我使用tap事件的時(shí)間非常敏感,因此我很好奇是否有可能在用戶(hù)簡(jiǎn)單按下時(shí)激活UITapGestureRecognizer,而不是要求他們同時(shí)按下嗎?
查看完整描述

3 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

創(chuàng)建您的自定義TouchDownGestureRecognizer子類(lèi),并在touches中實(shí)現(xiàn)手勢(shì)。


TouchDownGestureRecognizer.h


#import <UIKit/UIKit.h>


@interface TouchDownGestureRecognizer : UIGestureRecognizer


@end

TouchDownGestureRecognizer.m


#import "TouchDownGestureRecognizer.h"

#import <UIKit/UIGestureRecognizerSubclass.h>


@implementation TouchDownGestureRecognizer

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    if (self.state == UIGestureRecognizerStatePossible) {

        self.state = UIGestureRecognizerStateRecognized;

    }

}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    self.state = UIGestureRecognizerStateFailed;

}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    self.state = UIGestureRecognizerStateFailed;

}



@end

實(shí)施:


#import "TouchDownGestureRecognizer.h"

    TouchDownGestureRecognizer *touchDown = [[TouchDownGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouchDown:)];

    [yourView addGestureRecognizer:touchDown];


-(void)handleTouchDown:(TouchDownGestureRecognizer *)touchDown{

    NSLog(@"Down");

}

迅捷的實(shí)現(xiàn):


import UIKit

import UIKit.UIGestureRecognizerSubclass


class TouchDownGestureRecognizer: UIGestureRecognizer

{

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent)

    {

        if self.state == .Possible

        {

            self.state = .Recognized

        }

    }


    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent)

    {

        self.state = .Failed

    }


    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent)

    {

        self.state = .Failed

    }

}

這是2017年要粘貼的Swift語(yǔ)法:


import UIKit.UIGestureRecognizerSubclass


class SingleTouchDownGestureRecognizer: UIGestureRecognizer {

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {

        if self.state == .possible {

            self.state = .recognized

        }

    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {

        self.state = .failed

    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {

        self.state = .failed

    }

}

請(qǐng)注意,這是的替代品UITap。所以在像這樣的代碼中


func add(tap v:UIView, _ action:Selector) {

    let t = UITapGestureRecognizer(target: self, action: action)

    v.addGestureRecognizer(t)

}

您可以安全地交換到...。


func add(hairtriggerTap v:UIView, _ action:Selector) {

    let t = SingleTouchDownGestureRecognizer(target: self, action: action)

    v.addGestureRecognizer(t)

}

測(cè)試表明它不會(huì)被多次調(diào)用。它可以作為替代品。您可以在兩個(gè)通話之間進(jìn)行交換。


查看完整回答
反對(duì) 回復(fù) 2019-11-27
?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

使用UILongPressGestureRecognizer并將其設(shè)置minimumPressDuration為0。在UIGestureRecognizerStateBegan狀態(tài)期間,它將像著陸一樣。


對(duì)于Swift 4

func setupTap() {

    let touchDown = UILongPressGestureRecognizer(target:self, action: #selector(didTouchDown))

    touchDown.minimumPressDuration = 0

    view.addGestureRecognizer(touchDown)

}


@objc func didTouchDown(gesture: UILongPressGestureRecognizer) {

    if gesture.state == .began {

        doSomething()

    }

}

對(duì)于Objective-C

例:


-(void)setupLongPress

{

   self.longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPress:)];

   self.longPress.minimumPressDuration = 0;

   [self.view addGestureRecognizer:self.longPress];

}


-(void)didLongPress:(UILongPressGestureRecognizer *)gesture

{

   if (gesture.state == UIGestureRecognizerStateBegan){

      [self doSomething];

   }

}


查看完整回答
反對(duì) 回復(fù) 2019-11-27
?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

Swift(無(wú)子類(lèi))

這是Swift版本,類(lèi)似于Rob Caraway的Objective-C答案。


想法是使用minimumPressDuration設(shè)置為零的長(zhǎng)按手勢(shì)識(shí)別器,而不是使用輕擊手勢(shì)識(shí)別器。這是因?yàn)殚L(zhǎng)按手勢(shì)識(shí)別器報(bào)告觸摸開(kāi)始事件,而點(diǎn)擊手勢(shì)沒(méi)有報(bào)告。


import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var myView: UIView!


    override func viewDidLoad() {

        super.viewDidLoad()


        // Add "long" press gesture recognizer

        let tap = UILongPressGestureRecognizer(target: self, action: #selector(tapHandler))

        tap.minimumPressDuration = 0

        myView.addGestureRecognizer(tap)

    }


    // called by gesture recognizer

    @objc func tapHandler(gesture: UITapGestureRecognizer) {


        // handle touch down and touch up events separately

        if gesture.state == .began {

            // do something...

            print("tap down")

        } else if gesture.state == .ended { // optional for touch up event catching

            // do something else...

            print("tap up")

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-11-27
  • 3 回答
  • 0 關(guān)注
  • 660 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)