捏合视图变化(视图的缩放), 单击随着鼠标移动, 双击放大视图,再双击还原视图
来源:互联网 发布:图片裁剪软件 编辑:程序博客网 时间:2024/05/16 19:20
//// CLView.m// Homework_UIEvent//// Created by lanouhn on 14-8-26.// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.//#import "CLView.h"@interface CLView ()//{// CGPoint _firstPreviousLocation;// CGPoint _secondPreviousLocation;//}@end@implementation CLView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code self.multipleTouchEnabled = YES; } return self;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ static int i = 1; //双击放大, 再次双击恢复 if (1 == touches.count && 2 == [[touches anyObject] tapCount]) { if (1 == i % 2) { self.bounds = CGRectMake(0, 0, self.bounds.size.width * 3.0, self.bounds.size.height * 3.0); } else { self.bounds = CGRectMake(0, 0, self.bounds.size.width / 3.0, self.bounds.size.height / 3.0); } i++; }}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ }- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ }- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ //获取两个点移动之后的位置 NSArray *allTouches = [touches allObjects]; UITouch *firstTouch = [allTouches firstObject]; UITouch *secondTouch = [allTouches lastObject]; //获取两个手指之前的位置 CGPoint firstPreviousLocation = [firstTouch previousLocationInView:self]; CGPoint secondPreviousLocation = [secondTouch previousLocationInView:self]; //获取两个手指当前位置 CGPoint firstCurrentLocation = [firstTouch locationInView:self]; CGPoint secondCurrentLocation = [secondTouch locationInView:self]; //若只有一个手指触摸屏幕并移动时, view同样移动 if (1 == [touches count]) { self.center = CGPointMake(self.center.x + firstCurrentLocation.x - firstPreviousLocation.x, self.center.y + firstCurrentLocation.y - firstPreviousLocation.y); return; } //获取之前两个点的距离 CGFloat previousDistance = [self distanceOfPoint1:firstPreviousLocation point2:secondPreviousLocation]; //获取当前两个点的距离 CGFloat currentDistance = [self distanceOfPoint1:firstCurrentLocation point2:secondCurrentLocation]; // NSLog(@"%g", previousDistance); //求变化的比例 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));}/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect{ // Drawing code}*/@end
0 0
- 捏合视图变化(视图的缩放), 单击随着鼠标移动, 双击放大视图,再双击还原视图
- 视图的捏合(缩放)
- 视图的单击,双击,捏合,扫动,旋转,长按等。
- 9.2 触摸和手势:单击双击、移动视图
- IOS学习 触摸和手势UITouch 单击双击、移动视图
- Xamarin.iOS滑动视图上图片(视图)的缩放(双击手势实现缩放)
- 创建一个可移动的视图,让视图随着鼠标的移动而移动
- 视图的移动,旋转,缩放
- UITouch(事件)及其如何让视图随着鼠标移动
- 视图缩放
- 缩放视图
- IOS:实现对图片的双击放大、移动、捏合操作
- ADF 双击 Table 跳转到另一个视图
- 视图
- 视图
- 视图
- 视图
- 视图
- 用VS2013编译FFMPEG232
- android学习笔记——四大组件之Service
- UML序列图
- oracle在线重定义
- java的四种引用
- 捏合视图变化(视图的缩放), 单击随着鼠标移动, 双击放大视图,再双击还原视图
- 关于各种语言的发明时间,c语言为什么有些语法和Pascal相似
- 观察者模式
- Linux编译内核遇到找不到linux/limits.h的问题
- 对java的认识
- [翻译][Java]ExecutorService的正确关闭方法
- 百度的一道面试题(关于Cache的)
- unidac sqlite数据库字符集
- POJ 2359 Questions