zoukankan      html  css  js  c++  java
  • UISB 手势

    viewcontroller.h

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    {
        // 定义试图对象
        UIImageView* _imageView;
        
    }
    
    
    @end

    viewcontroller.m

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        //加载图像
        UIImage* image = [UIImage imageNamed:@"a.jpg"];
        
        _imageView=[[UIImageView alloc]init];
        
        _imageView.image= image;
        
        _imageView.frame=CGRectMake(50, 80, 200, 300);
        
        [self.view addSubview:_imageView];
        //YES 开启交互事件开关
        //NO 不能接受响应事件 默认为NO
        
        _imageView.userInteractionEnabled=YES;
        //创建一个点击手势对象
        //UITapGestureRecognizer 点击手势类NO
        //功能 识别手势事件
        //P1 响应事件的拥有对象 self 表示当前视图控制器
        //P2 响应事件的函数
        
        
        UITapGestureRecognizer* tapOneGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOneAct:)];
        
        //表示手势识别事件的事件类型 几个手指点击时触发
        //默认 1
        tapOneGes.numberOfTapsRequired=1;
        
        //表示几个手指点击时触发事件函数
        //默认值为1
        tapOneGes.numberOfTouchesRequired=1;
        //将点击事件添加到视图中 ,视图即可响应事件
        [_imageView addGestureRecognizer:tapOneGes];
        
        UITapGestureRecognizer* tapTwo=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwo:) ];
        
        tapTwo.numberOfTapsRequired=2;
        
        tapTwo.numberOfTouchesRequired=1;
        [_imageView addGestureRecognizer:tapTwo];
        // 当单击操作遇到双击操作时 单机操作失效
        [tapOneGes requireGestureRecognizerToFail:tapTwo];
        
      
    }
    //事件响应函数
    //参数 手势点击事件对象
    -(void)tapOneAct:(UITapGestureRecognizer*)tap
    {
        
        
        UIImageView* imageView = (UIImageView*) tap.view;
        
        imageView.frame = CGRectMake(0, 0, 320, 568);
        
    }
    
    
    
    -(void)tapTwo:(UITapGestureRecognizer*)tap
    {
        NSLog(@"双次点击");
        _imageView.frame= CGRectMake(50, 80, 200, 300);
        
    }
    
    @end
  • 相关阅读:
    安装原版Win8.1并激活
    Java8 List<对象> 转 Set、Map(高级)、排序、分组、统计
    SpringCloud第二弹(高可用Eureka+Ribbon负载均衡)
    SpringCloud第一弹(入门)
    SpringBoot+Shiro+Redis共享Session入门小栗子
    Go语言(IDEA下+Eclipse下)Hello World
    Linux学习杂谈
    小孩儿才分对错,成年人只看利弊
    Xshell5
    91 Testing MySQL学习总结
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13697667.html
Copyright © 2011-2022 走看看