• UIGesture点击手势


      1 //
      2 //  ViewController.m
      3 //  UIWindowsApp
      4 //
      5 //  Created by on 21/09/2017.
      6 //  8 
      9 #import "ViewController.h"
     10 #import "ViewController2.h"
     11 
     12 @interface ViewController ()
     13 
     14 @end
     15 
     16 @implementation ViewController
     17 
     18 
     19 
     20 
     21 - (void)viewDidLoad {
     22     [super viewDidLoad];
     23     
     24     UIImage* image = [UIImage imageNamed:@"1.jpg"];
     25     
     26     _imageView= [[UIImageView alloc]init];
     27     
     28     _imageView.image = image;
     29     
     30     _imageView.frame = CGRectMake(50, 100, 220, 300);
     31     
     32     _imageView.tag = 101;
     33     
     34     [self.view addSubview:_imageView];
     35 
     36     //是否开启交互事件响应开关,默认值为NO
     37     _imageView.userInteractionEnabled = YES;
     38     
     39     //P1:谁响应事件 P2:响应函数
     40     UITapGestureRecognizer* tapOneGes = [[UITapGestureRecognizer alloc]initWithTarget: self action:@selector(tapOneAct:)];
     41 
     42     
     43     //几次点击时触发,默认值为1。
     44     tapOneGes.numberOfTapsRequired = 1;//如果是2,而点击两次才会执行函数
     45     
     46     //几个手指点击时,触发此事件,默认值为1。
     47     tapOneGes.numberOfTouchesRequired =1 ;
     48     
     49     //将点击事件添加到视图中,视图即可响应事件
     50     [_imageView addGestureRecognizer:tapOneGes];
     51     
     52     
     53     UITapGestureRecognizer *tapTwo = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTwoAct:)];
     54 
     55     tapTwo.numberOfTapsRequired =2;
     56     
     57     tapTwo.numberOfTouchesRequired = 1;
     58     
     59     [_imageView addGestureRecognizer:tapTwo];
     60     
     61     //当单击操作遇到双击操作时,单击操作失效
     62     [tapOneGes requireGestureRecognizerToFail:tapTwo];
     63 
     64 }
     65 -(void) tapTwoAct:(UIGestureRecognizer*) tap
     66 {
     67     //开始动画过程
     68     [UIView beginAnimations:nil context:nil];
     69     
     70     //设置动画过渡时间
     71     [UIView setAnimationDuration:2];
     72     
     73     _imageView.frame = CGRectMake(50, 100, 220, 300);
     74     
     75     //结束动画过程
     76     [UIView commitAnimations];
     77 }
     78 
     79 
     80 
     81 
     82 -(void) tapOneAct:(UIGestureRecognizer*) tap
     83 {
     84     //NSLog(@"单击操作");
     85     UIImageView* imageView =(UIImageView*) tap.view;
     86     
     87     //开始动画过程
     88     [UIView beginAnimations:nil context:nil];
     89     
     90     //设置动画过渡时间
     91     [UIView setAnimationDuration:2];
     92     
     93     imageView.frame = CGRectMake(0, 0, 500, 600);
     94     
     95     //结束动画过程
     96     [UIView commitAnimations];
     97 }
     98 
     99 - (void)didReceiveMemoryWarning {
    100     [super didReceiveMemoryWarning];
    101     // Dispose of any resources that can be recreated.
    102 }
    103 
    104 
    105 @end
     1 //
     2 //  ViewController.h
     3 //  UIWindowsApp
     4 //
     5 
     6 //
     7 
     8 #import <UIKit/UIKit.h>
     9 
    10 @interface ViewController : UIViewController
    11 {
    12    
    13     UIImageView* _imageView;
    14     
    15 }
    16 
    17 //属性定义
    18 //@property(retain,nonatomic) UITextField* textField;
    19 
    20 
    21 
    22 
    23 @end 
  • 相关阅读:
    25个PHP游戏编程脚本代码(转)
    [AJAXJSP]使用DWR框架验证用户名是否存在
    [AJAXJSP]验证用户名存在
    [Java基础]多线程求和小例子
    [JAVA算法]求子数组的最大和
    [JQury] slideToggle闪烁问题及解决办法
    [JAVA算法]递归求Fibbonicc序列方法
    Easy ui Datagrid(下拉、复选、只输入数字、文本) 追加、删除、更改
    Easy ui DataGrid 添加复选框 与 下拉
    Easy ui DataGrid 列文字多串行问题解决方案
  • 原文地址:https://www.cnblogs.com/vector11248/p/7605856.html
Copyright © 2020-2023  润新知