8.4 Detecting Long Press Gestures

2024-03-01 10:18

本文主要是介绍8.4 Detecting Long Press Gestures,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

长按

#import "ViewController.h"


@interface ViewController ()


@property (nonatomic, strong) UILongPressGestureRecognizer *longPressGestureRecognizer;

@property (nonatomic, strong) UIButton *dummyButton;


@end


@implementation ViewController


- (void) handleLongPressGestures:(UILongPressGestureRecognizer *)paramSender{

    /* Here we want to find the midpoint of the two fingers

     that caused the long press gesture to be recognized. We configured this number using the numberOfTouchesRequired property of the UILongPressGestureRecognizer that we instantiated in the viewDidLoad instance method of this View Controller. If we

     find that another long press gesture recognizer is using this method as its target, we will ignore it */

    if ([paramSender isEqual:self.longPressGestureRecognizer]){

        if (paramSender.numberOfTouchesRequired == 2){

        CGPoint touchPoint1 = [paramSender locationOfTouch:0 inView:paramSender.view];

        CGPoint touchPoint2 = [paramSender locationOfTouch:1 inView:paramSender.view];

        CGFloat midPointX = (touchPoint1.x + touchPoint2.x) / 2.0f;

        CGFloat midPointY = (touchPoint1.y + touchPoint2.y) / 2.0f;

        CGPoint midPoint = CGPointMake(midPointX, midPointY);

        self.dummyButton.center = midPoint;

    } else {

        /* This is a long press gesture recognizer with more

         or less than 2 fingers */

    }

    }

}


- (void)viewDidLoad

{

    [super viewDidLoad];

   

    

    

    self.view.backgroundColor = [UIColor whiteColor];

    self.dummyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    self.dummyButton.frame = CGRectMake(0.0f,0.0f, 72.0f, 37.0f);

    self.dummyButton.center = self.view.center;

    [self.view addSubview:self.dummyButton];

    /* First create the gesture recognizer */

    self.longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc]

                                       initWithTarget:self action:@selector(handleLongPressGestures:)];

    /* The number of fingers that must be present on the screen */

    self.longPressGestureRecognizer.numberOfTouchesRequired = 2;

    /* Maximum 100 points of movement allowed before the gesture is recognized */

    self.longPressGestureRecognizer.allowableMovement = 100.0f;

    /* The user must press two fingers (numberOfTouchesRequired) for at least one second for the gesture to be recognized */

    self.longPressGestureRecognizer.minimumPressDuration = 1.0;

    /* Add this gesture recognizer to the view */

    [self.view addGestureRecognizer:self.longPressGestureRecognizer];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



实现的效果是:长按屏幕上的两点,1秒钟后,按钮自动跳到这两点的中间,这时可进行移动

这篇关于8.4 Detecting Long Press Gestures的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/762101

相关文章

java中long的一些常见用法

《java中long的一些常见用法》在Java中,long是一种基本数据类型,用于表示长整型数值,接下来通过本文给大家介绍java中long的一些常见用法,感兴趣的朋友一起看看吧... 在Java中,long是一种基本数据类型,用于表示长整型数值。它的取值范围比int更大,从-922337203685477

java Long 与long之间的转换流程

《javaLong与long之间的转换流程》Long类提供了一些方法,用于在long和其他数据类型(如String)之间进行转换,本文将详细介绍如何在Java中实现Long和long之间的转换,感... 目录概述流程步骤1:将long转换为Long对象步骤2:将Longhttp://www.cppcns.c

《数据结构(C语言版)第二版》第八章-排序(8.3-交换排序、8.4-选择排序)

8.3 交换排序 8.3.1 冒泡排序 【算法特点】 (1) 稳定排序。 (2) 可用于链式存储结构。 (3) 移动记录次数较多,算法平均时间性能比直接插入排序差。当初始记录无序,n较大时, 此算法不宜采用。 #include <stdio.h>#include <stdlib.h>#define MAXSIZE 26typedef int KeyType;typedef char In

long long,_int64使用小结

前言:   在16位环境下,int/unsigned int 占16位,long/unsigned long占32位   在32位环境下,int占32位,unsigned int占16位,long/unsigned long占32位 何时需要使用:   long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647,而unsigned范围是[0,2^32),

《长得太长也是错?——后端 Long 型 ID 精度丢失的“奇妙”修复之旅》

引言 在前后端分离的时代,我们的生活充满了无数的机遇与挑战——包括那些突然冒出来的让人抓狂的 Bug。今天我们要聊的,就是一个让无数开发者哭笑不得的经典问题:后端 Long 类型 ID 过长导致前端精度丢失。说到这个问题,那可真是“万恶之源”啊,谁让 JavaScript 只能安全地处理 Number.MAX_SAFE_INTEGER(也就是 9007199254740991)以内的数值呢?

踩坑记录(Long[]ids)

主要针对Long[] ids 的判空问题 问题代码 public void delYnjC(Long[] ids) {if (CollectionUtils.isEmpty(Collections.singleton(ids))) {throw new NullPointerException("参数不能为空");}naturalYnjCMapper.delYnjC(ids);} 修正

CodeForces 407B Long Path

题意: 有n+1个格子  起点在1  每个格子有个前进1的门  前n个格子有个返回的门(返回前面某个格子)  奇数次走进一个格子就去走返回门  偶数次走前进门  问  走到n+1要走过几道门 思路: 一看就是DP to[i]表示第i个格子的返回门 go[i]表示离开第i个格子需要的步数 sum[i]表示离开前i个格子需要的步数 明显  go[i]=sum[i-1]-sum[to

Command line is too long. Shorten command line for DisplayApplication (1) or

微服务项目启动类起不来,如下 解决办法:IEDA开发环境下 找到你的项目下面的.idea\workspace.xml 添加一个property : <property name="dynamic.classpath" value="true" /> 帮同事看的问题,自己测试没问题就关闭了。图片借用网上的。 参考:参考

[C++] 将LONG类型的color值转换为RGB值

转换原理: The calculation is: (65536 * Blue) + (256 * Green) + (Red) 'Convert RGB to LONG: LONG = B * 65536 + G * 256 + R       'Convert LONG to RGB:  B = LONG \ 65536  G = (LONG - B * 65536) \ 256  R =