【UI基础】手势识别
来源:互联网 发布:php curl 不返回头部 编辑:程序博客网 时间:2024/04/27 22:23
//
// ViewController.m
// 09-手势识别器
//
// Created by styshy on 15/11/2.
// Copyright (c) 2015年 sz. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutletUIImageView *imgView;
@end
@implementation ViewController
// 手势调节
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 点按收拾
// [self addTap];
// 长按收拾
// [self longPress];
// 清扫
// [self addSwipe];
// 旋转
// [self addRotation];
// 捏合收拾
// [self addPinch];
// 拖拽
[self addPan];
}
#pragma mark - / ******** 拖拽方式实现 **********/
- (void)addPan{
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(pan:)];
[self.imgViewaddGestureRecognizer:pan];
}
- (void)pan:(UIPanGestureRecognizer *)pan{
// 获取移动的点
CGPoint point = [pan translationInView:self.imgView];
NSLog(@"%@",NSStringFromCGPoint(point));
self.imgView.transform =CGAffineTransformTranslate(self.imgView.transform, point.x, point.y);
// 复位
[pan setTranslation:CGPointZeroinView:self.imgView];
}
#pragma mark - / ******** UIGestureRecoginzerDelegate方法 **********/
// 是否可以同时执行多个手势
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
// 手势是否开始,参数是手势类型
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
NSLog(@"%@",gestureRecognizer);
return YES;
}
// 是否允许接收Touch
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
return YES;
}
#pragma mark - / ******** 捏合方式实现 **********/
- (void)addPinch{
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinch:)];
[self.imgViewaddGestureRecognizer:pinch];
// 属性设置,缩放比例和缩放大小
pinch.delegate = self;
// 同时设置旋转
[selfaddRotation];
}
- (void)pinch:(UIPinchGestureRecognizer *)pinch{
self.imgView.transform =CGAffineTransformScale(self.imgView.transform, pinch.scale, pinch.scale);
pinch.scale = 1;
}
#pragma mark - / ******** 旋转方式实现 **********/
- (void)addRotation{
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotation:)];
rotation.delegate = self;
[self.imgViewaddGestureRecognizer:rotation];
}
// 让图片选装
- (void)rotation:(UIRotationGestureRecognizer *)rotation{
self.imgView.transform =CGAffineTransformRotate(self.imgView.transform, rotation.rotation);
rotation.rotation = 0;
}
#pragma mark - / ******** 清扫方式实现 **********/
- (void)addSwipe{
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipe:)];
// 设置清扫方向
swipe.direction =UISwipeGestureRecognizerDirectionLeft |UISwipeGestureRecognizerDirectionRight;
[self.imgViewaddGestureRecognizer:swipe];
}
- (void)swipe:(UISwipeGestureRecognizer *)swipe{
NSLog(@"%s",__func__);
}
#pragma mark - / ******** 点按收拾实现 **********/
- (void)longPress{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPress:)];
[self.imgViewaddGestureRecognizer:longPress];
}
- (void)longPress:(UILongPressGestureRecognizer *)longPress{
// 方法默认对调用2次,解决方案是判断状态
if(longPress.state ==UIGestureRecognizerStateBegan){
NSLog(@"%s",__func__);
}
}
#pragma mark - / ******** 点按收拾实现 **********/
- (void)addTap{
// 点按收拾
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap)];
[self.imgViewaddGestureRecognizer:tap];
}
- (void)tap{
NSLog(@"%s",__func__);
}
@end
- 【UI基础】手势识别
- UI基础-设计模式、手势识别器
- UI--手势识别器
- android基础--手势识别
- UI控件 - 手势识别
- UI基础之---手势
- Android基础:手势识别:GestureDetector
- Android手势识别基础介绍
- UI笔记_手势识别器
- UI之手势识别器 注意
- UI课程05 设计模式,手势识别
- iOS基础3:手势识别之谈
- 【UI基础】手势解锁简单实现
- UI基础学习之(十四):手势
- UI进阶第十发:Quartz 2D手势识别
- 随意细解:UI -- 设计模式、手势识别
- UI 第五天 代理设计模式 手势识别器
- 进击的KFC:UI(五)手势识别器
- 安卓应用程序的组成部分
- LightOJ - 1150 Ghosts!(二分图+bfs+枚举)
- Java中String为什么是Immutable的
- PhantomJS快速入门教程
- 每天学一点linux(三)
- 【UI基础】手势识别
- 教你看懂redis配置_codepython整理四
- 单调栈
- MySQL 5.6.26安装mysql-5.6.26-win64.zip绿色版
- c++11特性之std::thread--初识二
- 对数据定义的认识
- 2015-11-02-01-当年尝试应聘F7海外技术支持所写的英文自我介绍
- iOS开发:下载视频到沙盒
- 如何发布Node模块到NPM社区