美文网首页
iOS UITouch基础操作

iOS UITouch基础操作

作者: futur_zwl | 来源:发表于2017-08-14 16:45 被阅读0次

UITouch

手指的触摸范围:64X64

#pragma mark Touch Events

- (void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event {originFrame = bookCover.frame;

NSLog(@"%s %d", __FUNCTION__,__LINE__);

if ([touches count] == 2)

{

NSArray *twoTouches = [touches allObjects];

UITouch *firstTouch = [twoTouches objectAtIndex:0];

UITouch *secondTouch = [twoTouches objectAtIndex:1];

CGPoint firstPoint = [firstTouch locationInView:bookCover];CGPoint secondPoint = [secondTouch locationInView:bookCover];

CGFloat deltaX = secondPoint.x - firstPoint.x;

CGFloat deltaY = secondPoint.y - firstPoint.y;initialDistance = sqrt(deltaX * deltaX + deltaY * deltaY );frameX = bookCover.frame.origin.x;

frameY = bookCover.frame.origin.y;

frameW = bookCover.frame.size.width;

frameH = bookCover.frame.size.height;

NSLog(@"%s %d", __FUNCTION__,__LINE__);

}

}

- (void)touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event {

if([touches count] == 2)

{

NSLog(@"%s %d", __FUNCTION__,__LINE__);

NSArray *twoTouches = [touches allObjects];

UITouch *firstTouch = [twoTouches objectAtIndex:0];UITouch *secondTouch = [twoTouches objectAtIndex:1];

CGPoint firstPoint = [firstTouch locationInView:bookCover];

CGPoint secondPoint = [secondTouch locationInView:bookCover];

CGFloat deltaX = secondPoint.x - firstPoint.x;

CGFloat deltaY = secondPoint.y - firstPoint.y;

CGFloat currentDistance = sqrt(deltaX * deltaX + deltaY * deltaY );

if (initialDistance == 0) {

initialDistance = currentDistance;

}

else if (currentDistance != initialDistance)

{

CGFloat changedDistance = currentDistance - initialDistance;NSLog(@"changedDistance = %f",changedDistance);

[bookCover setFrame:CGRectMake(frameX - changedDistance / 2,frameY - (changedDistance * frameH) / (2 * frameW),

frameW + changedDistance,

frameH + (changedDistance * frameH) / frameW)];

}

}

}

- (void)touchesEnded:(NSSet *) touches withEvent:(UIEvent *) event {

UITouch *touch = [touches anyObject];

UITouch双击图片变大/还原

if ([touch tapCount] == 2)

{

NSLog(@"%s %d", __FUNCTION__,__LINE__);

if (!flag) {

[bookCover setFrame:CGRectMake(bookCover.frame.origin.x - bookCover.frame.size.width / 2,bookCover.frame.origin.y - bookCover.frame.size.height / 2,

2 * bookCover.frame.size.width,

2 * bookCover.frame.size.height)];

flag = YES;

}

else {

[bookCover setFrame:CGRectMake(bookCover.frame.origin.x + bookCover.frame.size.width / 4,bookCover.frame.origin.y + bookCover.frame.size.height / 4,

bookCover.frame.size.width / 2, bookCover.frame.size.height / 2)];

flag = NO;

}

}

}

Get the Location of Touches

(CGPoint)locationInView:(UIView *)view

(CGPoint)previousLocationInView:(UIView *)view

view window

Getting Touch Attributes

tapCount(read only) timestamp(read only) phase(read only)

Getting a Touch Object's Gesture Recognizers

gestureRecognizers

Touch Phase

UITouchPhaseBegan

UITouchPhaseMoved

UITouchPhaseStationary

UITouchPhaseEnded

UITouchPhaseCancelled

相关文章

  • iOS UITouch基础操作

    UITouch 手指的触摸范围:64X64 #pragma mark Touch Events - (void)t...

  • iOS UITouch

    UITouch UITouch的属性 触摸产生时所处的窗口 @property(nonatomic,readonl...

  • UITouch触摸操作

    1. 触摸操作的生命周期 手指触摸屏幕的瞬间在这个过程中,可以通过 touch.tapCount 判断是单击还是双...

  • IOS开发 UITouch

    本节学习内容: 1.UITouch的基本概念 2.UITouch的作用周期 3.UITouch的应用 【viewC...

  • 触摸事件、事件传递(响应者、响应者链)、手势

    UITouch官方教程UIGesturereCognizer官方教程 参考教程 事件处理demo IOS当中常用的...

  • iOS响应链

    当用户的手指点击屏幕的时候,iOS操作系统通过触摸屏获取用户的点击行为,然后把这个点击信息包装成UITouch和U...

  • iOS触摸事件详解

    目录:1 UITouch1.1 UITouch的创建1.2 UITouch的作用1.3 UITouch的常用属性1...

  • iOS 字符串操作

    iOS之字符串截取、替换、分隔、匹配 其他基础操作

  • iOS_UITouch 事件

    转载自简书:http://www.jianshu.com/p/3e3a62b131f5 做电商搜索页面的时候,热门...

  • iOS_UITouch 事件

    UITouch 基本事件函数 UITouch 包含如下四个基本函数,touches 集合中存储的事UITouch ...

网友评论

      本文标题:iOS UITouch基础操作

      本文链接:https://www.haomeiwen.com/subject/inwurxtx.html