码迷,mamicode.com
首页 > 移动开发 > 详细

IOS第15天(1,事件处理View的拖拽)

时间:2015-08-31 16:51:06      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

*******view 一些方法

#import "HMView.h"

@implementation HMView
// 一个完整的触摸过程
// touchesBegan -> touchesMoved -> touchesEnded

/*
    NSArray 集合 有序
    NSSet 无序

 */

// 触摸开始
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 获取一个UITouch
    UITouch *touch = [touches anyObject];
    
//     NSLog(@"%s----%d",__func__,touches.count);
//    NSLog(@"%d",touch.tapCount);
//    NSLog(@"%d",touch.phase);
}
// 手指移动
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 获取一个UITouch
    UITouch *touch = [touches anyObject];
    
    // 获取当前的位置
    CGPoint current = [touch locationInView:self];
    // 获取上一个点
    CGPoint pre = [touch previousLocationInView:self];
    
    // x轴偏移量
    CGFloat offsetX = current.x - pre.x;
    CGFloat offsetY = current.y - pre.y;
    NSLog(@"%@",NSStringFromCGPoint(current));
    
    // 获取视图的center
    CGPoint center = self.center;
    center.x += offsetX;
    center.y += offsetY;
    self.center = center;


}

// 触摸结束
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 获取一个UITouch
    UITouch *touch = [touches anyObject];
//      NSLog(@"%d",touch.phase);
//    NSLog(@"%s----%p",__func__,touch);

}

// 触摸被打断 比如打电话过来
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

@end

 

IOS第15天(1,事件处理View的拖拽)

标签:

原文地址:http://www.cnblogs.com/ios-g/p/4773151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!