UITouch 的使用

直接上代码:

touch 的四大状态,:
//
//  TouchView.m
//  UI_practice_04
//
//  Created by lanouhn on 15/4/22.
//  Copyright (c) 2015年 huangyankai. All rights reserved.
//

#import "TouchView.h"
//延展
@interface TouchView ()
@property (nonatomic,assign) CGPoint startPoint;//记录当前起始点坐标

@end

@implementation TouchView
//方法是功能片段的封装。
//触摸开始  表示手指接触到屏幕时,会触发
//图层

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%s",__FUNCTION__);
//    CGcolor另一个框架   给UIColor发一个消息,转化为CGColor 设置阴影
//    设置阴影的颜色
    self.layer.shadowColor = [[UIColor lightGrayColor] CGColor];
//    设置阴影的偏移量
    self.layer.shadowOffset = CGSizeMake(10, 10);
//    设置阴影不透明度
    self.layer.shadowOpacity = 0.9;
//    角半径
    self.layer.cornerRadius = 100;

    UITouch *aTouch = [touches anyObject];
//    获取触摸开始点并保存
    self.startPoint = [aTouch locationInView:self.superview];
}

//触摸移动,当手指触摸屏幕并产生移动的时候,会重复调用此方法
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%s",__FUNCTION__);
    UITouch *aTouch = [touches anyObject];
//    父视图上的一个点
    CGPoint currentPoint = [aTouch locationInView:self.superview];
//    通过移动产生的当前触摸点和上一个触摸点的X和Y轴的增量
    CGFloat delta_x = currentPoint.x - self.startPoint.x;
    CGFloat delta_y = currentPoint.y - self.startPoint.y;
//    通过视图当前起始点坐标以及delta_x和delta_y来推算新的起始点坐标
    CGRect frame = self.frame;
    frame.origin.x += delta_x;
    frame.origin.y += delta_y;
    self.frame = frame;
//   将当前点保存下来,成为下一次移动产生的新的点的计算增量依据
    self.startPoint = currentPoint;

}

//触摸结束,表示手指离开屏幕时触发
//NSSet集合,无序性
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%s",__FUNCTION__);
    self.layer.shadowColor = nil;
    self.layer.shadowOffset = CGSizeZero;
    self.layer.shadowOpacity = 0;

}
//触摸取消,表示此时手指并未离开屏幕,但是由于一些打断(来电话)而失去与该视图的交互
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%s",__FUNCTION__);
}
@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 02:09:15

UITouch 的使用的相关文章

UITouch触摸事件

UITouch触摸事件 主要为三个方法 1.-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{2.3. UITouch *touch = [touches anyObject];4. CGPoint point = [touch locationInView:self];5. start = point;6. end = point;7.8.}9.10.-(void)touchesMoved:(NSSet *)touc

UITouch手指滑动屏幕,屏幕跟着移动

1.//当手指在屏幕上滑动时 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch  = [touches anyObject]; CGPoint previousPoint = [touch previousLocationInView:self]; CGPoint currentPoint = [touch locationInView:self]; CGPoint newCenter

iOS:触摸控件UITouch、事件类UIEvent

UITouch:触摸控件类   UIEvent:事件类 ??????UITouch的介绍?????? 一.触摸状态类型枚举 typedef NS_ENUM(NSInteger, UITouchPhase) { UITouchPhaseBegan,             // 开始触摸 UITouchPhaseMoved,             // 触摸移动 UITouchPhaseStationary,       // 触摸没有移动 UITouchPhaseEnded,        

利用uitouch简单的实现了微信cell效果

#import <UIKit/UIKit.h> @interface weixinControl : UIControl -(weixinControl *)initWithFram:(CGRect)rect; @end #import "weixinControl.h" @implementation weixinControl { CGRect _rect; //记录self.frame的大小 UIView *_frontView; //用来显示主要内容 CGPoint

进击的UI---------------------UIEvent&amp;UITouch&amp;UIResponder

1.UIEvent(事件) 1??:事件分为三种:1 触摸事件 2 晃动事件 3 远程控制 2??:触摸事件 //1. UIControlEventTouchUpInside     点击进去(点后松手) //2. UIControlEventTouchDown         单击(点就出) //3. UIControlEventTouchDownRepeat   双击 //4. UIControlEventTouchDragInside   点一点,拽一拽(Button内) //5. UIC

触摸事件UITouch的应用

因为UIView或者UIViewController都是继承与UIResponder ,所以都有UITouch这个事件.当用户点击屏幕的时候,会产生触摸事件. 通过UITouch事件,可以监听到开始触摸.触摸移动过程.触摸结束以及触摸打断四个不同阶段的状态,在这些方法中,我们能够获取到很多有用的信息,比如触摸点的坐标.触摸的手指数.触摸的次数等等,下面通过一个小例子来说明一下. 详细代码如下: /* 定义属性 */ @interface ViewController () { CGPoint _

UITouch 触摸事件处理(转载)

1. UITouch 的主要方法: C代码   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NS

IOS开发——UI进阶篇(十二)事件处理,触摸事件,UITouch,UIEvent,响应者链条,手势识别

触摸事件 在用户使用app过程中,会产生各种各样的事件 一.iOS中的事件可以分为3大类型 触摸事件加速计事件远程控制事件 响应者对象在iOS中不是任何对象都能处理事件,只有继承了UIResponder的对象才能接收并处理事件.我们称之为“响应者对象” UIApplication.UIViewController.UIView都继承自UIResponder,因此它们都是响应者对象,都能够接收并处理事件 二.UIResponder UIResponder内部提供了以下方法来处理事件触摸事件- (v

UIScrollView不接受UITouch事件的解决方法

原因是:UIView的touch事件被UIScrollView捕获了. 解决办法:让UIScrollView将事件传递过去.于是最简单的解决办法就是加一个UIScrollView的category.这样每个用到UIScrollView的地方只要导入这个category就可以直接响应相关的touch事件了.我也是从别人的那参考过来的,纪录一下. 直接上代码 #import "UIScrollView+UITouch.h" @implementation UIScrollView (UIT

你真的了解UIEvent、UITouch吗?

一:首先查看一下关于UIEvent的定义 //事件类型 typedef NS_ENUM(NSInteger, UIEventType) { UIEventTypeTouches, UIEventTypeMotion, UIEventTypeRemoteControl, }; // 触摸事件的类型 typedef NS_ENUM(NSInteger, UIEventSubtype) { UIEventSubtypeNone = 0, //摇晃  UIEventSubtypeMotionShake