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));
}
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));
}
相关文章推荐
- iOS自定义转场详解03——实现通过圆圈放大缩小的转场动画
- 利用iOS手势与scrollView代理实现图片的放大缩小
- 手机实现手势操作的类-放大,缩小,旋转水平垂直方向
- iOS中用按钮NSbutton实现视图的放大与缩小功能
- ImageView通过matrix实现手势缩放,放大,缩小 ,移动
- C#初学者——通过ICommad接口实现mxd的打开、保存、放大、缩小、平移、全局显示、前后视图等
- iOS开发——手势识别器(用手势实现图片旋转和缩小放大)
- IOS中常用手势:手指向右滑动和向左滑动屏幕实现固定操作
- ios简单手势操作-模态视图
- android 自定义ImageView实现图片手势滑动,多点触摸放大缩小效果
- iOS用UIScrollView实现图片的放大和缩小(包括双击图片放大或缩小)
- IOS中常用手势:手指向右滑动和向左滑动屏幕实现固定操作
- android 自定义ImageView实现图片手势滑动,多点触摸放大缩小效果
- 图片放大、缩小、恢复操作的实现
- 图片点击放大,再次点击返回原视图.完美封装,一个类一句代码即可调用.IOS完美实现
- ios 根据手势放大或缩小图片
- [iOS]手势操作实现图片的缩放
- ios 通过VOIP 实现后台操作
- ios 根据手势放大或缩小图片
- android 自定义ImageView实现图片手势滑动,多点触摸放大缩小效果 .