8.3 Detecting Panning and Dragging Gestures

2024-03-01 10:18

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

拖动

@interface ViewController ()


@property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;

@property (nonatomic, strong) UILabel *helloWorldLabel;


@end


@implementation ViewController


- (void) handlePanGestures:(UIPanGestureRecognizer*)paramSender{

    NSLog(@"paramSender.view=%@",paramSender.view);

    //UIGestureRecognizerStateEnded xy可能会是个不正常的值

    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){

        CGPoint location = [paramSender locationInView:paramSender.view.superview];

        paramSender.view.center = location;

//        self.helloWorldLabel.center = location;

    }

}


-(UILabel*)getALable:(NSString*)text X:(NSInteger)x Y:(NSInteger)y

{

    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 80)];

    lable.text = text;

    lable.backgroundColor = [UIColor blackColor];

    lable.textColor = [UIColor whiteColor];

    lable.textAlignment = NSTextAlignmentCenter;

    lable.userInteractionEnabled = YES;

    return lable;

}


-(UIPanGestureRecognizer*)getPanGestureRecognizer

{

    UIPanGestureRecognizer * pgr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestures:)];

    pgr.minimumNumberOfTouches = 1;

    pgr.maximumNumberOfTouches = 1;

    

    return pgr;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

   

    

    

    self.view.backgroundColor = [UIColor whiteColor];

    

    self.helloWorldLabel = [self getALable:@"Hello World" X:50 Y:50];

    

    [self.view addSubview:self.helloWorldLabel];

    

    UILabel * lable2 = [self getALable:@"Hello world 2" X:50 Y:200];

    

    [self.view addSubview:lable2];

    

    /* Create the Pan Gesture Recognizer */

    self.panGestureRecognizer = [self getPanGestureRecognizer];

    /* Add it to the view */

    [self.helloWorldLabel addGestureRecognizer:self.panGestureRecognizer];

    //这里要重新创建一个新的GestrueRecognizer对象,否则self.helloWorldLabel就识别不了了

    [lable2 addGestureRecognizer:[self getPanGestureRecognizer]];

//    [self.view addGestureRecognizer:self.panGestureRecognizer];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


由于有两个label,且都加上了PanGestureRecognizer,我们可以通知拉着他们移动

输出:

2014-04-10 10:56:48.026 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (50 50; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.041 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (97.5 49.5; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.043 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (98.5 50; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.057 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (98.5 50; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.073 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (99 51; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.089 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (99.5 51.5; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.105 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (100 52; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.121 cookbook[860:907] paramSender.view=<UILabel: 0x1f8441c0; frame = (50 200; 200 80); text = 'Hello world 2'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844c40>; layer = <CALayer: 0x1f844250>>

2014-04-10 10:56:48.124 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (100.5 52.5; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>

2014-04-10 10:56:48.137 cookbook[860:907] paramSender.view=<UILabel: 0x1f8441c0; frame = (80 211; 200 80); text = 'Hello world 2'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844c40>; layer = <CALayer: 0x1f844250>>

2014-04-10 10:56:48.139 cookbook[860:907] paramSender.view=<UILabel: 0x1f842ee0; frame = (101 53; 200 80); text = 'Hello World'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f844aa0>; layer = <CALayer: 0x1f842fc0>>













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



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

相关文章

《数据结构(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

第八章 【后端】环境准备(8.3)——VirtualBox

8.3 VirtualBox VirtualBox 官网 VirtualBox 是一款开源虚拟机软件。VirtualBox 是由德国 Innotek 公司开发,由 Sun Microsystems 公司出品的软件,使用 Qt 编写,在 Sun 被 Oracle 收购后正式更名成 Oracle VM VirtualBox。 下载 安装 一路“下一步”,建议安装到非系统盘。 注意:要开

【C++ Primer Plus习题】8.3

问题: 解答: #include <iostream>#include <string>#include <cctype>using namespace std;void function(string& str){for (int i = 0; i < str.size(); i++){str[i]=toupper(str[i]);}}int main(){strin

EmguCV学习笔记 C# 8.3 Grabcut法

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。 EmguCV是一个基于OpenCV的开源免费的跨平台计算机视觉库,它向C#和VB.NET开发者提供了OpenCV库的大部分功能。 教程VB.net版本请访问:EmguCV学习笔记 VB.Net 目录-CSDN博客 教程C#版本请访问:EmguCV学习笔记 C# 目录-CSDN博客 笔者的

在 CentOS 7 上安装 LNMP 环境:MySQL 8.0、PHP 8.3 和 ThinkPHP 8.0

在 CentOS 7 上安装 LNMP 环境,并配置 MySQL 8.0、PHP 8.3 以及 ThinkPHP 8.0,能够为你的 web 应用程序提供一个强大的开发和运行环境。下面是详细的安装步骤: --- ## 在 CentOS 7 上安装 LNMP 环境:MySQL 8.0、PHP 8.3 和 ThinkPHP 8.0 查看本机系统 cat /etc/os-release #

8.3 数据库基础技术-关系代数

并、交、差 笛卡尔积、投影、选择 自然连接 真题

Mysql 8.3.0 安装

Mysql 8.3.0 安装地址:MySQL :: Download MySQL Community Server (Archived Versions) 下载链接:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.3.0-linux-glibc2.28-x86_64.tar.xz  解压: tar -xvf mysq

《PixelLink: Detecting Scene Text via Instance Segmentation》论文阅读笔记

前言 这篇论文发表在AAAI2018上,作者给出了源码,个人认为是一篇比较work的论文。在之前DPR和SegLink两篇论文的阅读过程中,我就曾思考二者multi-task的必要性。特别是DPR的classification task,其实跟segment是几乎等价的。在复现过程中,回归任务远比分类(分割)任务难收敛。 可以认为,在自然场景下的文本检测任务中,DPR证明了anchor的非必要性

CVPR2017《Detecting Oriented Text in Natural Images by Linking Segments》阅读笔记

前言 本文是对CVPR2017《Detecting Oriented Text in Natural Images by Linking Segments》论文的简要介绍和细节分析。该论文是华中科大白翔组的工作,主要针对自然场景下文本检测模型由char-level到word-level和line-level的检测。 关键词:SSD、Segment、Link、Scene Text Detectio

《软件方法(下)》8.3.4.6 DDD话语“聚合”中的伪创新(2)

DDD领域驱动设计批评文集 做强化自测题获得“软件方法建模师”称号 《软件方法》各章合集 《软件方法》最新pdf和epub文件:umlchina.com/url/softmeth2024.html 8.3 建模步骤C-2 识别类的关系 8.3.4 识别关联关系 8.3.4.6 DDD话语“聚合”中的伪创新 (3)aggregate root是伪创新 (续前文) aggre