要缩小通过两个触摸点的观点(iOS)
于AppDelegate.m档,创建一个视图控制器
#import "MAYAppDelegate.h"
#import "MAYViewController.h"
@implementation MAYAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MAYViewController *root = [[MAYViewController alloc] init];
self.window.rootViewController = root;
[root release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
创建一个视图控制器MAYViewController,在视图控制器MAYViewController.m文件里,创建一个视图
#import "MAYViewController.h"
#import "Touch.h"
@interface MAYViewController ()
@end
@implementation MAYViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor lightGrayColor];
Touch *touch = [[Touch alloc] initWithFrame:CGRectMake(50, 150, 200, 200)];
touch.backgroundColor = [UIColor greenColor];
[self.view addSubview:touch];
[touch release];
}
新建一个视图类Touch,加入在视图控制器上,在Touch.m文件里实现缩放功能
#import "Touch.h"
@implementation Touch
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//设置是否支持多点触摸(YES支持,NO不支持)
self.multipleTouchEnabled = YES;
}
return self;
}
//计算两点之间的距离
- (CGFloat)distance:(CGPoint)point1 point2:(CGPoint)point2
{
CGFloat dx = point1.x - point2.x;
CGFloat dy = point1.y - point2.y;
CGFloat tance = sqrt(pow(dx, 2) + pow(dy, 2));
return tance;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (1 == [touches count]) {
return;
}
//设置触摸点
NSArray *array = [touches allObjects];
UITouch *touch1 = [array firstObject];
UITouch *touch2 = [array lastObject];
//获取移动前的触摸点
CGPoint firstPreviousPoint = [touch1 previousLocationInView:self];
CGPoint secondPreviousPoint = [touch2 previousLocationInView:self];
//获取与移动后的触摸点
CGPoint firstCurrentPoint = [touch1 locationInView:self];
CGPoint secondCurrentPoint = [touch2 locationInView:self];
//获取移动前后的两点之间的距离
CGFloat previousDistance = [self distance:firstPreviousPoint point2:secondPreviousPoint];
CGFloat currentDistance = [self distance:firstCurrentPoint point2:secondCurrentPoint];
//获取缩放比例
CGFloat scanl = currentDistance / previousDistance;
//获得缩放后的视图大小
self.bounds = CGRectMake(0, 0, self.bounds.size.width * scanl, self.bounds.size.height * scanl);
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
要缩小通过两个触摸点的观点(iOS)的更多相关文章
- Android与IOS的优缺点比较 对 Android 与 IOS 比较是个个人的问题。 就好比我来说,我两个都用。我深知这两个平台的优缺点。所以,我决定分享我关于这两个移动平台的观点。另外,然后谈谈我对新的 Ubuntu 移动平台的印象和它的优势。 IOS 的优点 虽然这些天我是个十足的 Android 用户,但我必须承认 IOS 在某些方面做的是不错。首先,苹果公司在他们的设备更新方面有更
Android与IOS的优缺点比较 对 Android 与 IOS 比较是个个人的问题. 就好比我来说,我两个都用.我深知这两个平台的优缺点.所以,我决定分享我关于这两个移动平台的观点.另外,然后谈谈 ...
- Unity3D-实现连续点击两次返回键退出游戏(安卓/IOS)
Unity3D-连续点击两次返回键退出游戏 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Count ...
- iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事 ...
- [转]starling教程-触摸事件(Touch Events)(四)
在前面提到过,Starling是Sparrow的姊妹篇,正因为这样,Starling里的touch事件的机制其实是为移动设备的触摸交互设计的,所以当你使用它进行使用鼠标交互的桌面应用开发时,第一眼会感 ...
- javascript触摸事件touch使用
详细内容请点击 Apple在iOS 2.0中引入了触摸事件API,Android正迎头赶上这一事实标准,缩小差距.最近一个W3C工作组正合力制定这一触摸事件规范. 在本文深入研究iOS和 ...
- ios开发——实用技术OC-Swift篇&触摸与手势识别
iOS开发学习之触摸事件和手势识别 iOS的输入事件 触摸事件 手势识别 手机摇晃 一.iOS的输入事件 触摸事件(滑动.点击) 运动事件(摇一摇.手机倾斜.行走),不需要人为参与的 远程控制 ...
- 转发:iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
-- iOS事件全面解析 转载来自崔江涛(KenshinCui) 链接:http://www.cnblogs.com/kenshincui/p/3950646.html 概览 iPhone的成功很大一 ...
- iOS_触摸事件与手势识别
目 录: 一.触摸事件 1.1iOS的输入事件 1.2 触摸事件的处理 1.3 UITouch类中包含五个属性 1.4 UITouch类中包含两个成员函数 1.5响应者链 二.手势识别 2.1使用手 ...
- cocos2d CCLayer 触摸相关
要让一个 CCLayer 能够接受触摸输入 需要进行如下设置: [selfsetTouchEnabled:YES]; cocos2d-x提供了两种触摸事件处理机制, 分别是CCStandardTo ...
随机推荐
- adb shell - device not found
如果是真机,则连接usb即可(我的是真机).
- dotnet与各种数据库类型对应关系
Data Provider Parameter format sqlclient @parametername oledb ? mark odbc ? mark oracleclient : ...
- UIWebView执行JS语句
示例网页: http://m.dianping.com/tuan/deal/moreinfo/11507109 移除该网页的返回按钮, 购买链接, 最底部的友情链接 代码: NSMutableStri ...
- jQuery实现checkbox全选反选及删除等操作
1.list.html 说明:用checkbox数组Check[]存放每一行的ID值 <div id="con"> <table width="100% ...
- jquery工具函数browser() 辨别浏览器
1.browser属性不是一个函数是一个全局对象,可以辨别客户端浏览器. 2.属性1:$.browser.msie如果返回true则客户端浏览器是ie.相似的$.browser.safari返回tru ...
- js中的模块化编写思维
作为一个新手程序员,在编程时一定要刻意锻炼自己的模块化编写思路,但是究竟什么才是模块化编写对于新人来说还是不太能够直观的理解,下面就举个简单的例子来说明一下 概念:最早接触模块化的说法是从java上, ...
- java-二分查找法
package search; public class BinarySearch { public static void main(String[] args) { , , , , , , , , ...
- Android之Activity生命周期简介
概述 有图有真相,所以先上图: 上图是从Android官网截下的Activity的生命周期流程图,结构非常清晰,它描述了Activity在其生命周期中所有可能发生的情况以及发生的先后顺序,下面就将结合 ...
- MVC中的过滤器
authour: chenboyi updatetime: 2015-05-09 09:30:30 friendly link: 目录: 1,思维导图 2,过滤器种类(图示) 3,全局过滤器 ...
- codeforces 232D Fence
John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the righ ...