您的位置:首页 > 移动开发 > IOS开发

iOS不通过手势 实现 放大 缩小视图操作

2014-08-26 21:19 597 查看
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

if ([touches count] ==
1) {

return;

}

NSArray *touchesArr = [touches
allObjects];

UITouch *firstTouch = [touchesArr
firstObject];

UITouch *secondTouch = [touchesArr
lastObject];

CGPoint previousPoint1 = [firstTouch
previousLocationInView:self];

CGPoint previousPoint2 = [secondTouch
previousLocationInView:self];

CGPoint currentPoint1 = [firstTouch
locationInView:self];

CGPoint currentPoint2 = [secondTouch
locationInView:self];

CGFloat previousDistance = [self
distanceOfPoint1:previousPoint1
point2:previousPoint2];

CGFloat currentDistance = [self
distanceOfPoint1:currentPoint1
point2:currentPoint2];

CGFloat scale = currentDistance / previousDistance;

self.bounds =
CGRectMake(0,
0, self.bounds.size.width * scale,
self.bounds.size.height *scale);

}

-(CGFloat)distanceOfPoint1:(CGPoint)point1 point2:(CGPoint)point2{

CGFloat dx = point1.x - point2.x;

CGFloat dy = point1.y - point2.y;

return sqrt(pow(dx,
2) + pow(dy,
2));

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: