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

*******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
时间: 2025-01-18 09:00:02

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

iOS 未读消息角标 仿QQ拖拽 简单灵活 支持xib(源码)

一.效果 二.简单用法 超级简单,2行代码集成:xib可0代码集成,只需拖一个view关联LFBadge类即可 支持pod导入pod 'LFKit/LFBadge' //一般view上加角标 _badge1 = [[LFBadge alloc] init]; [_badge1 addToTabBarItem:_view1]; //BarButtonItem上加角标 _badge2 = [[LFBadge alloc] init]; [_badge2 addToBarButtonItem:self

IOS第15天(2,事件处理hitTest练习)

***hitTest 获取最合适的点 @implementation HMGreenView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"%s",__func__); } // 获取 最合适的 点的view //- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event //{ // // 把自己的点转换按钮的坐标系上

IOS第15天(3,事件处理,手势处理)

7> 手势识别    使用UIImageView原因:之前既能看见图片,又能监听点击的只有UIButton,学了手势,我们的UIImageView也可以.    * tap(代理:左边不能点,右边能点)    * longPress(allowableMovement:触发之前,最大的移动范围)        > 默认调用两次,开始一次,结束一次.    * swipe:(一个手势只能识别一个方向)    * 旋转:      基于上一次旋转    * 复位:(手势的取值都是相对最原始的位置,

IOS第15天(2,事件处理,侧滑菜单,抽屉效果)

******HMDrawViewController.m #import "HMDrawViewController.h" @interface HMDrawViewController () @property (nonatomic, assign) BOOL isDraging; @end @implementation HMDrawViewController - (void)viewDidLoad { // UIViewController [super viewDidLoad

猫猫学IOS(三十六)UI之手势事件旋转_缩放_拖拽

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 源码:http://blog.csdn.net/u013357243/article/details/45560213 效果 完成一个图片的捏合缩放,拖拽,旋转动作. 设计思路 拖拽: 首先是最简单的拖拽 //拖拽 -(void)panTest { UIPanGestureRecognizer *pan = [[UIPanGe

(素材源码)猫猫学IOS(三十六)UI之手势事件旋转_缩放_拖拽

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 源码:http://download.csdn.net/detail/u013357243/8671943 效果 完成一个图片的捏合缩放,拖拽,旋转动作. 代码:NYViewController.m // // NYViewController.m // 旋转_缩放_拖拽 // // Created by apple on 1

iOS开发——实用技术OC篇&事件处理详解

事件处理详解 一:事件处理 事件处理常见属性: 事件类型 @property(nonatomic,readonly) UIEventType     type; @property(nonatomic,readonly) UIEventSubtype  subtype; 事件产生的时间 @property(nonatomic,readonly) NSTimeInterval  timestamp; 事件传递 - hitTest:withEvent: SWIFT func hitTest(_ po

【IOS笔记】Creating Custom Content View Controllers

Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of your app. You use them to present your app’s unique content. All apps need at least one custom content view controller. Complex apps divide the workl

iOS开发UI篇—控制器的View的创建

iOS开发UI篇—控制器的View的创建 一.6种创建控制器View的方式 1 #import "NJAppDelegate.h" 2 #import "NJViewController.h" 3 /* 4 1.没有同名xib情况下 5 2.通过 storyboard 创建 6 3.有指定xib情况下创建 7 4.有同名xib情况 8 5.有同名去掉controll的情况 9 6.loadveiw 10 */ 11 @implementation NJAppDele