iOS UITouch基础操作

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iphone开发笔记 退回输入键盘 - (BOOL) textFieldShouldReturn:(id)text...
    爱易寒曲易散阅读 3,759评论 0 1
  • 退回输入键盘 -(BOOL)textFieldShouldReturn:(id)textField{ [textF...
    韩七夏阅读 3,576评论 0 0
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 5,486评论 2 4
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,715评论 6 30
  • 彼岸花开四季鸟语花香 我在岸这头 彼岸人流涌动川流不息 我在岸这头 彼岸焕彩夺目姹紫嫣红 我在岸这头 待到这江干渴...
    晴天映白云阅读 2,578评论 2 0