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