UI2_UIGesture
//
// ViewController.h
// UI2_UIGesture
//
// Created by zhangxueming on 15/7/9.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIGestureRecognizerDelegate> @end
//
// ViewController.m
// UI2_UIGesture
//
// Created by zhangxueming on 15/7/9.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *names = @[@"blue",@"red",@"yellow"];
for (int i=0; i<3; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100*i, 180+100*i, 100, 100)];
imageView.image = [UIImage imageNamed:names[i]];
[self.view addSubview:imageView];
//打开用户交互使能
imageView.userInteractionEnabled = YES; //添加点击手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
//设置点击次数
tap.numberOfTapsRequired = 1;
//设置手指个数
tap.numberOfTouchesRequired = 2;
//给imageView 添加手势
[imageView addGestureRecognizer:tap]; //添加长按手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
longPress.numberOfTapsRequired = 0;
//longPress.numberOfTouchesRequired = 2;
[imageView addGestureRecognizer:longPress]; //添加移动手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[imageView addGestureRecognizer:pan]; //捏合手势
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
[imageView addGestureRecognizer:pinch];
//旋转手势
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[imageView addGestureRecognizer:rotation];
//轻扫手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[imageView addGestureRecognizer:swipe];
}
} - (void)tapGesture:(UITapGestureRecognizer *)tap
{
NSLog(@"图片被点击");
} - (void)longPressGesture:(UILongPressGestureRecognizer *)longPress
{
NSLog(@"长按手势被触发");
} - (void)panGesture:(UIPanGestureRecognizer *)pan
{
NSLog(@"移动手势被触发");//5 10 15 5 5 5
UIView *view = pan.view;//5+5+5
//获取手势的偏移量
CGPoint px = [pan translationInView:self.view];
if(pan.state == UIGestureRecognizerStateBegan || pan.state == UIGestureRecognizerStateChanged)
{
//改变手势对应的view中心点坐标
pan.view.center = CGPointMake(view.center.x+px.x, view.center.y+px.y);
}
//设置偏移量为0;
[pan setTranslation:CGPointZero inView:self.view];
} - (void)pinchGesture:(UIPinchGestureRecognizer *)pinch
{
NSLog(@"捏合手势被触发");
if(pinch.scale == UIGestureRecognizerStateBegan || pinch.scale ==UIGestureRecognizerStateChanged)
{
pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
}
//设置系数为1
pinch.scale = 1.0;
} - (void)rotationGesture:(UIRotationGestureRecognizer *)rotation
{
NSLog(@"旋转手势被触发");
if (rotation.state == UIGestureRecognizerStateBegan || rotation.state == UIGestureRecognizerStateChanged) {
rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
} rotation.rotation = 0.0;
} - (void)swipeGesture:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"轻扫手势被触发");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI2_UIGesture的更多相关文章
随机推荐
- 《Java虚拟机原理图解》 1.2、class文件里的常量池
[最新更新:2014/11/11] 了解JVM虚拟机原理 是每个Java程序猿修炼的必经之路. 可是因为JVM虚拟机中有非常多的东西讲述的比較宽泛.在当前接触到的关于JVM虚拟机原理的教程或者博客中 ...
- OS_TASK.C
/*************************************************************************************************** ...
- ssl/https双向验证的配置
1.SSL认证 不需要特别配置,相关证书库生成看https认证中的相关部分 2.HTTPS认证 一.基本概念 1.单向认证,就是传输的数据加密过了,但是不会校验客户端的来源 2.双向认证,如果客户端 ...
- 解决Github使用Fastly CDN而导致不能加载网页的方法 转自 沙丘:http://www.enkoo.net/fastly-cdn-in-gifhub.html
Github现在基本属于“安全”网站,但Github使用fastly.net的CDN服务后,其网站在国内经常不能正常加载网页.github.global.ssl.fastly.net的亚洲IP一般为1 ...
- 一款基于css3的3D图片翻页切换特效
今天给大家分享一款基于css3的3D图片翻页切换特效.单击图片下方的滑块会切换上方的图片.动起你的鼠标试试吧,效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id= ...
- Disruptor 源码阅读笔记--转
原文地址:http://coderbee.net/index.php/open-source/20130812/400 一.Disruptor 是什么? Disruptor 是一个高性能异步处理框架, ...
- 让Laravel5支持memcache的方法
Laravel5框架在Cache和Session中不支持Memcache,看清了是Memcache而不是Memcached哦,MemCached是支持的但是这个扩展真的是装的蛋疼,只有修改部分源码让其 ...
- C# 使用GDI+绘制漂亮的MenuStrip和ContextMenuStrip皮肤
通过上面的效果截图可以看到,重绘后的MenuStrip和ContextMenuStrip可以添加自己的LOGO信息,实现了类似OFFICE2007的菜单显示效果. .NET对菜单控件的绘制提供了一个抽 ...
- Python笔记(二)
在昨天学习Python之后,感觉它的的确确挺简洁,也挺容易学习.在昨天的学习中我们了解到了Python中while循环语句以及if...else语句的使用,while语句的使用格式是这样的:while ...
- SQL 必知必会-- 第17课:创建和操作表
我这里用的是oracle 10g,PL/SQL来做的. 第17课 创建和操纵表 14517.1 创建表 14517.2 更新表 15017.3 删除表 15317.4 重命名表 1 ...