search

Home  >  Q&A  >  body text

ios - 有什么方法可以判断是否有手指放在屏幕上。

有个需求需要判断使用者是否有手指放在屏幕上。
貌似没有这样的方法。

PHP中文网PHP中文网2889 days ago448

reply all(5)I'll reply

  • 迷茫

    迷茫2017-04-18 09:18:02

    Determine whether the current runloop is in tracking mode. If so, it means a finger is touching the screen

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:18:02

    Rewrite several methods of Touches, Begin and End

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:18:02

    • (void)touchesBegan:(NSSet<UITouch > )touches withEvent:(UIEvent *)event{

    }

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

    }

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

    }

    I don’t know if this is what the questioner is talking about

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:18:02

    Add the following method in AppDelegate.m

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        NSLog(@"开始触摸");
    }
    
    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        NSLog(@"结束触摸");
    }

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:18:02

    Swift writing method
    If it is global, add it to AppDelegate.swift
    If it is a certain view, add it to the corresponding ViewController.swift

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        print("开始触摸")
    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        print("结束触摸")
    }

    reply
    0
  • Cancelreply