zoukankan      html  css  js  c++  java
  • iOS---给视图添加手势

     初始化手势同时添加手势事件---把手势添加到视图上

    // 1.轻拍手势类 // 创建一个轻拍手势 同时绑定了一个事件 UITapGestureRecognizer *aTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)]; // 设置轻拍次数 aTapGR.numberOfTapsRequired = 1; // 设置手指触摸的个数 aTapGR.numberOfTouchesRequired = 2; // 添加手势 [self.rootView addGestureRecognizer:aTapGR]; [aTapGR release]; // 2.长按手势 UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; [self.rootView addGestureRecognizer:longPressGR]; [longPressGR release]; // 3.旋转手势 UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)]; [self.rootView.testImageView addGestureRecognizer:rotationGR]; [rotationGR release]; // 4.捏合手势 UIPinchGestureRecognizer *pinchRG = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)]; [self.rootView addGestureRecognizer:pinchRG]; [pinchRG release]; // 5.平移手势 UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGRAction:)]; [self.rootView.testImageView addGestureRecognizer:panGR]; [panGR release]; // 6.轻扫手势 UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGRAction:)]; // 设置滑动方向 默认是从左往右 swipeGR.direction = UISwipeGestureRecognizerDirectionLeft; // 设置向左滑动 [self.rootView.testImageView addGestureRecognizer:swipeGR]; [swipeGR release]; // 7.屏幕边缘轻扫识别器 UIScreenEdgePanGestureRecognizer *screenPGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgeGRAction:)]; [self.rootView addGestureRecognizer:screenPGR]; [screenPGR release];
  • 相关阅读:
    Luogu P4892 GodFly的寻宝之旅【状压dp】By cellur925
    Luogu P1092 虫食算【搜索/剪枝】 By cellur925
    搜索之蜜汁剪枝
    Luogu P1514引水入城【搜索】 By cellur925
    Luogu P1074靶形数独【搜索/剪枝】By cellur925
    常用算法(冒泡、插入、选择、快速)和二叉树详解
    Java面试常问问题及答案(非常详细)
    GitHub代码上传教程
    停更一段时间
    线程之间状态和转换(新建、就绪、运行、阻塞、死亡)
  • 原文地址:https://www.cnblogs.com/bachl/p/4695921.html
Copyright © 2011-2022 走看看