首页 > 移动平台 > 详细

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

时间:2015-08-31 16:48:01      阅读:233      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!