• UITouch


     1 //
     2 //  ViewController.m
     3 //  UIWindowsApp
     4 //
     5 //  Created by  on 21/09/2017.
     6 //  Copyright © 2017 . All rights reserved.
     7 //
     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     UIImageView* iView = [[UIImageView alloc]init];
    27     
    28     iView.image = image;
    29     
    30     iView.frame = CGRectMake(50, 100, 220, 300);
    31     
    32     iView.tag = 101;
    33     
    34     [self.view addSubview:iView];
    35 
    36     
    37 }
    38 //手指触碰到屏幕
    39 -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    40 {
    41     UITouch* touch = [touches anyObject];
    42     if(touch.tapCount == 1)
    43     {
    44         NSLog(@"单击"); //
    45     }else if(touch.tapCount == 2)
    46     {
    47         NSLog(@"双击666");//双击时会触发单击事件,什么鬼???
    48     }
    49     _mPtLast = [touch locationInView:self.view];
    50     NSLog(@"手指触碰瞬间");
    51 }
    52 //手指接触到屏幕,并且没有离开时被调用
    53 -(void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    54 {
    55     UITouch * touch = [touches anyObject];
    56     
    57     CGPoint pt = [touch locationInView:self.view];
    58     
    59     float xOffset = pt.x - _mPtLast.x;
    60     float yOffset = pt.y - _mPtLast.y;
    61     
    62     _mPtLast = pt;
    63     
    64     UIImageView * view  =(UIImageView*)[self.view viewWithTag:101];
    65     
    66     view.frame = CGRectMake(view.frame.origin.x+xOffset, view.frame.origin.y+yOffset, view.frame.size.width, view.frame.size.height);
    67     
    68     
    69     NSLog(@"x = %f,y=%f",pt.x,pt.y);
    70     
    71 }
    72 //手指离开时被调用
    73 -(void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    74 {
    75     NSLog(@"手指离开时被调用");
    76 }
    77 
    78 // 特殊情况下的中段事件,例如电话,信息切入时,会取消当前的手势。
    79 // 用来做紧急的数据保存等
    80 -(void) touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    81 {
    82     NSLog(@"");
    83 }
    84 
    85 
    86 
    87 - (void)didReceiveMemoryWarning {
    88     [super didReceiveMemoryWarning];
    89     // Dispose of any resources that can be recreated.
    90 }
    91 
    92 
    93 @end
     1 //
     2 //  ViewController.h
     3 //  UIWindowsApp
     4 //
     5 //  Created by
     6 //  Copyright ©
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 
    11 @interface ViewController : UIViewController
    12 {
    13    
    14     CGPoint _mPtLast;
    15     
    16     
    17 }
    18 
    19 //属性定义
    20 //@property(retain,nonatomic) UITextField* textField;
    21 
    22 
    23 
    24 
    25 @end 
  • 相关阅读:
    Linux下JDK安装位置
    Oracle中的User与Schema
    MFC中不同窗口间的切换
    MFC 动态的画线 画当前的线是清除上一次画的线
    VC ADO连接ACCESS步骤及错误处理
    虚继承和虚函数继承
    虚拟机无法连接连接U盘
    未能找到类型或命名空间
    VS2008 重构 封装字段 出错 无法使用
    vs2010 Visual Studio 遇到了异常。这可能是由某个扩展导致的
  • 原文地址:https://www.cnblogs.com/vector11248/p/7603891.html
Copyright © 2020-2023  润新知