数码控科技猎奇Iphone动漫星座游戏电竞lolcosplay王者荣耀攻略allcnewsBLOGNEWSBLOGASKBLOGBLOGZSK全部技术问答问答技术问答it问答代码软件新闻开发博客电脑/网络手机/数码笔记本电脑互联网操作系统软件硬件编程开发360产品资源分享电脑知识文档中心IT全部全部分类 全部分类技术牛文全部分类教程最新 网页制作cms教程平面设计媒体动画操作系统网站运营网络安全服务器教程数据库工具网络安全软件教学vbscript正则表达式javascript批处理更多»编程更新教程更新游戏更新allitnewsJava 新闻网络医疗信息化安全创业站长电商科技访谈域名会议专栏创业动态融资创投创业学院 / 产品经理创业公司人物访谈营销 开发数据库服务器系统虚拟化云计算 嵌入式移动开发作业作业1常见软件all电脑网络手机数码生活游戏体育运动明星影音休闲爱好文化艺术社会民生教育科学医疗健康金融管理情感社交地区其他电脑互联网软件硬件编程开发360相关产品手机平板其他电子产品摄影器材360硬件通讯智能设备购物时尚生活常识美容塑身服装服饰出行旅游交通汽车购房置业家居装修美食烹饪单机电脑游戏网页游戏电视游戏桌游棋牌游戏手机游戏小游戏掌机游戏客户端游戏集体游戏其他游戏体育赛事篮球足球其他运动球类运动赛车健身运动运动用品影视娱乐人物音乐动漫摄影摄像收藏宠物幽默搞笑起名花鸟鱼虫茶艺彩票星座占卜书画美术舞蹈小说图书器乐声乐小品相声戏剧戏曲手工艺品历史话题时事政治就业职场军事国防节日风俗法律法规宗教礼仪礼节自然灾害360维权社会人物升学入学人文社科外语资格考试公务员留学出国家庭教育学习方法语文物理生物工程学农业数学化学健康知识心理健康孕育早教内科外科妇产科儿科皮肤科五官科男科整形中医药品传染科其他疾病医院两性肿瘤科创业投资企业管理财务税务银行股票金融理财基金债券保险贸易商务文书国民经济爱情婚姻家庭烦恼北京上海重庆天津黑龙江吉林辽宁河北内蒙古山西陕西宁夏甘肃青海新疆西藏四川贵州云南河南湖北湖南山东江苏浙江安徽江西福建广东广西海南香港澳门台湾海外地区

使用手势UIGestureRecognizer对图像进行缩放、移动、旋转操??/a>[代码]
鉴客

来源:本网整理
iOS提供了拍击、旋转、滑动、挤捏等丰富的手势,因此对图像的操作就显得非常友好、简单。下面代码展示了使用UIGestureRecognizer对图像进行缩放、移动、旋转操作使用方法??

在使用代码之前,首先建立一个UIView,并在该视图中增加一个UIImageView视图,用于展示图像。那么该UIView就类似图像画板一样,对图像的操作都基于此视图中进行??
http://www.ctolive.com/space-1023-do-blog-id-2109.html
scrolltotop.offset(100,120); scrolltotop.init();

[1].[代码] 在视图中创建手势识别器UIGestureRecognizers 跳至 [1] [2]

- (void)viewDidLoad {
    [super viewDidLoad];

    UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)] autorelease];
    [pinchRecognizer setDelegate:self];
    [self.view addGestureRecognizer:pinchRecognizer];

    UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease];
    [rotationRecognizer setDelegate:self];
    [self.view addGestureRecognizer:rotationRecognizer];

    UIPanGestureRecognizer *panRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)] autorelease];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [panRecognizer setDelegate:self];
    [canvas addGestureRecognizer:panRecognizer];

    UITapGestureRecognizer *tapProfileImageRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)] autorelease];
    [tapProfileImageRecognizer setNumberOfTapsRequired:1];
    [tapProfileImageRecognizer setDelegate:self];
    [canvas addGestureRecognizer:tapProfileImageRecognizer];
}

[2].[代码] 下面是响应各手势消息的方法: 跳至 [1] [2]

// 缩放
-(void)scale:(id)sender {

    if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
      _lastScale = 1.0;
    }

    CGFloat scale = 1.0 - (_lastScale - [(UIPinchGestureRecognizer*)sender scale]);

    CGAffineTransform currentTransform = photoImage.transform;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);

    [photoImage setTransform:newTransform];

    _lastScale = [(UIPinchGestureRecognizer*)sender scale];
    [self showOverlayWithFrame:photoImage.frame];
}

// 旋转
-(void)rotate:(id)sender {

    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

      _lastRotation = 0.0;
      return;
    }

    CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

    CGAffineTransform currentTransform = photoImage.transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

    [photoImage setTransform:newTransform];

    _lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
    [self showOverlayWithFrame:photoImage.frame];
}

// 移动
-(void)move:(id)sender {

  CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:canvas];

  if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
    _firstX = [photoImage center].x;
    _firstY = [photoImage center].y;
  }

  translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);

  [photoImage setCenter:translatedPoint];
  [self showOverlayWithFrame:photoImage.frame];
}
SyntaxHighlighter.autoloader( 'applescript /js/sh309/scripts/shBrushAppleScript.js?t=1451961936000', 'actionscript3 as3 /js/sh309/scripts/shBrushAS3.js?t=1451961936000', 'bash shell /js/sh309/scripts/shBrushBash.js?t=1451961936000', 'coldfusion cf /js/sh309/scripts/shBrushColdFusion.js?t=1451961936000', 'cpp c /js/sh309/scripts/shBrushCpp.js?t=1451961936000', 'obj-c objc /js/sh309/scripts/shBrushObjC.js?t=1451961936000', 'c# c-sharp csharp /js/sh309/scripts/shBrushCSharp.js?t=1451961936000', 'css /js/sh309/scripts/shBrushCss.js?t=1451961936000', 'delphi pascal /js/sh309/scripts/shBrushDelphi.js?t=1451961936000', 'diff patch pas /js/sh309/scripts/shBrushDiff.js?t=1451961936000', 'erl erlang /js/sh309/scripts/shBrushErlang.js?t=1451961936000', 'groovy /js/sh309/scripts/shBrushGroovy.js?t=1451961936000', 'haxe hx /js/sh309/scripts/shBrushHaxe.js?t=1451961936000', 'java /js/sh309/scripts/shBrushJava.js?t=1451961936000', 'jfx javafx /js/sh309/scripts/shBrushJavaFX.js?t=1451961936000', 'js jscript javascript /js/sh309/scripts/shBrushJScript.js?t=1451961936000', 'perl pl /js/sh309/scripts/shBrushPerl.js?t=1451961936000', 'php /js/sh309/scripts/shBrushPhp.js?t=1451961936000', 'text plain /js/sh309/scripts/shBrushPlain.js?t=1451961936000', 'py python /js/sh309/scripts/shBrushPython.js?t=1451961936000', 'ruby rails ror rb /js/sh309/scripts/shBrushRuby.js?t=1451961936000', 'scala /js/sh309/scripts/shBrushScala.js?t=1451961936000', 'sql /js/sh309/scripts/shBrushSql.js?t=1451961936000', 'vb vbnet /js/sh309/scripts/shBrushVb.js?t=1451961936000', 'xml xhtml xslt html /js/sh309/scripts/shBrushXml.js?t=1451961936000' ); SyntaxHighlighter.all();

  • 本文相关:
  • 使用Objective-C创建UUID的代??/a>[代码]
    鉴客
  • 一个很方便控制视图控件Z轴层次的UIView类别??Category)
  • UIView背景的渐??/a>[代码]
    鉴客
  • iOS设备多点触控和屏幕坏点检测程序代??/a>[代码]
    鉴客
  • tableview滚动到最后一行自动加载数??
  • iPhone toolchain 4.0 的两个配套示例代??/a>[代码]
    鉴客
  • IOS 使用 HTTP POST 上传图片和文本信??/a>[代码]
    红薯
  • UITextField限制字数的方??
  • NSMutableURLRequest,在POST方式下传递参??/a>[代码]
    鉴客
  • iPhone开??download 下载文件
  • 免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2017 www.zgxue.com All Rights Reserved