IOS学习 触摸和手势UITouch 捏合
2016-03-14 17:49
323 查看
@implementation HomeViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
touchView = [[UIView
alloc]initWithFrame:CGRectMake(0,
20,
self.view.bounds.size.width,
500)];
touchView.backgroundColor = [UIColor
cyanColor];
[self.view
addSubview:touchView];
//是否支持多点触摸,默认为NO
touchView.multipleTouchEnabled =
YES ;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([touches count] ==
2 ) {
//将两个手指信息内容取出来
NSArray *touchArray = [touches
allObjects];
UITouch *firstTouch = [touchArray
objectAtIndex:0];
UITouch *secondTouch = [touchArray
objectAtIndex:1];
//获取两个手指的坐标点
CGPoint firstPoint = [firstTouch
locationInView:touchView];
CGPoint secondPoint = [secondTouch
locationInView:touchView];
//计算两点距离
double distance = [self
distance:firstPoint
point:secondPoint];
NSLog(@"distance = %lf",distance);
}
}
//传入两个点参数,计算两点距离
- (double)distance:(CGPoint) p1 point:(CGPoint)p2{
//((x1-x2)平方+(y1-y2)平方)开方
pow平方 sqrt开方
double distance =
sqrt(pow(p1.x-p2.x,
2.0)+pow(p1.y-p2.y,
2.0));
return distance;
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([touches count] ==
2 ) {
//将两个手指信息内容取出来
NSArray *touchArray = [touches
allObjects];
UITouch *firstTouch = [touchArray
objectAtIndex:0];
UITouch *secondTouch = [touchArray
objectAtIndex:1];
//获取两个手指的坐标点
CGPoint firstPoint = [firstTouch
locationInView:touchView];
CGPoint secondPoint = [secondTouch
locationInView:touchView];
//计算两点距离
double distance = [self
distance:firstPoint
point:secondPoint];
double subValue = distance -lastValue;
if (subValue >
0) {
NSLog(@"放大");
}else{
NSLog(@"缩小");
}
lastValue = distance;
}
}
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
touchView = [[UIView
alloc]initWithFrame:CGRectMake(0,
20,
self.view.bounds.size.width,
500)];
touchView.backgroundColor = [UIColor
cyanColor];
[self.view
addSubview:touchView];
//是否支持多点触摸,默认为NO
touchView.multipleTouchEnabled =
YES ;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([touches count] ==
2 ) {
//将两个手指信息内容取出来
NSArray *touchArray = [touches
allObjects];
UITouch *firstTouch = [touchArray
objectAtIndex:0];
UITouch *secondTouch = [touchArray
objectAtIndex:1];
//获取两个手指的坐标点
CGPoint firstPoint = [firstTouch
locationInView:touchView];
CGPoint secondPoint = [secondTouch
locationInView:touchView];
//计算两点距离
double distance = [self
distance:firstPoint
point:secondPoint];
NSLog(@"distance = %lf",distance);
}
}
//传入两个点参数,计算两点距离
- (double)distance:(CGPoint) p1 point:(CGPoint)p2{
//((x1-x2)平方+(y1-y2)平方)开方
pow平方 sqrt开方
double distance =
sqrt(pow(p1.x-p2.x,
2.0)+pow(p1.y-p2.y,
2.0));
return distance;
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([touches count] ==
2 ) {
//将两个手指信息内容取出来
NSArray *touchArray = [touches
allObjects];
UITouch *firstTouch = [touchArray
objectAtIndex:0];
UITouch *secondTouch = [touchArray
objectAtIndex:1];
//获取两个手指的坐标点
CGPoint firstPoint = [firstTouch
locationInView:touchView];
CGPoint secondPoint = [secondTouch
locationInView:touchView];
//计算两点距离
double distance = [self
distance:firstPoint
point:secondPoint];
double subValue = distance -lastValue;
if (subValue >
0) {
NSLog(@"放大");
}else{
NSLog(@"缩小");
}
lastValue = distance;
}
}
相关文章推荐
- CodeForces 622A Infinite Sequence
- 可变字符串改变颜色大小
- UE4 添加多人联机功能
- UE4 添加多人联机功能
- UILabel的minimumScaleFactor
- EasyUI-draggable
- Basic build issue regarding libs, pkg-config and opencv
- IOS UICollectionView 的基础使用
- 根据sql的hash_value查看sql的正直执行计划
- UIButton设置内容setTitle
- 自定义UISearchBar
- 【HDU】 5538 House Building
- 自定义UITableViewCell(registerNib: 与 registerClass: 的区别)
- Android UiAutomator 初试。
- UITableView的总结
- IOS学习 触摸和手势UITouch 单击双击、移动视图
- Android进阶UI之SwipeListView左滑删除例子
- Android进阶UI之SlidingTabLayout实现ViewPager页卡滑动效果
- Android bluetooth介绍(一):基本概念及硬件接口
- 使用CSS3 Media Queries实现网页自适应