//
// RQHViewController.m
// Demo
//
// Created by apple on 15-1-5.
// Copyright (c) 2015年 __MyCompanyName__. All rights reserved.
//#import "RQHViewController.h"
@implementation RQHViewController
@synthesize smallView;- (void)viewDidLoad
{
[super viewDidLoad];
//捏合
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGesture:)];
[self.smallView addGestureRecognizer:pinch];
//滑动
UIPanGestureRecognizer *tap = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture:)];
[self.smallView addGestureRecognizer:tap];
//旋转
UIRotationGestureRecognizer *rotain = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGesture:)];
[self.smallView addGestureRecognizer:rotain];
//长按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGesture:)];
[self.smallView addGestureRecognizer:longPress];
}- (void)pinchGesture:(UIPinchGestureRecognizer* )gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
UIView *view = gesture.view;
view.frame = CGRectInset(view.frame, (1 - gesture.scale) *CGRectGetWidth(view.frame), (1 - gesture.scale) * CGRectGetHeight(view.frame));
[gesture setScale:1.0f];
}
break;
default:
break;
}
}- (void)tapGesture:(UIPanGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
CGPoint point = [gesture translationInView:gesture.view];
UIView *view = gesture.view;
view.frame = CGRectOffset(view.frame, point.x, point.y);
[gesture setTranslation:CGPointZero inView:view]; }
break;
default:
break;
}
}- (void)rotationGesture:(UIRotationGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
UIView *view = gesture.view;
view.transform = CGAffineTransformMakeRotation(gesture.rotation);
}
break;
default:
break;
}
}- (void)longPressGesture:(UILongPressGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateBegan:
{
UIMenuItem *item = [[UIMenuItem alloc]initWithTitle:@"hi" action:@selector(reset:)];
UIMenuController* menuController = [UIMenuController sharedMenuController];
menuController.menuItems = [NSArray arrayWithObject:item];
[menuController setTargetRect:CGRectMake(gesture.view.center.x, gesture.view.center.y, 0, 0) inView:self.view];
[menuController setMenuVisible:YES animated:YES];
}
break;
default:
break;
}
}- (void)reset:(UIMenuItem *)item
{
NSLog(@"------------hehehehe");
}//longPress需要写这个方法才能显示
- (BOOL)canBecomeFirstResponder {
return YES;
}@end
IOS-手势
时间: 2024-10-12 22:24:35
IOS-手势的相关文章
iOS手势学习UIGestureRecognizer &; cocos2d 手势推荐
iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer // 长按UIPanGestureRecognizer // 慢速拖动UIPinchGestureRecognizer // 两指向內或向外拨动UIRotationGestureRecognizer // 旋转UISwipeGestureRecognizer // 快速滑动UITapGestureRecognizer //
iOS手势 规避同一界面上不同子界面同时响应多个手势
最近在项目中遇到这样一个有关iOS手势的问题,首先需求描述如下:“在一个CollectionView中,要求长按不同的cell,产生一个cell的snapshot,此时可拖拽这个snapshot再进行后续的操作(如拖到view的某个位置出发一个事件)”.需求本身并不复杂,但要求每次只能有一个cell响应长按手势,不允许同时有两个或以上的cell响应长按手势. 我们知道UIGestureRecognizer有很多回调和方法可以兼容同一个View上的多种手势,网上相关的教程也很多,比如: http:
iOS手势UIGestureRecognizer
UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有6个子类处理具体的手势: 1.UITapGestureRecognizer (任意手指任意次数的点击) // 点击次数 numberOfTapsRequired // 手指个数 numberOfTouchesRequired [plain] view plaincopy UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer a
iOS手势UIGestureRecognizer识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 
(转)
1.UIGestureRecognizer介绍 手势识别在iOS上非常重要,手势操作移动设备的重要特征,极大的增加了移动设备使用便捷性. iOS系统在3.2以后,为方便开发这使用一些常用的手势,提供了UIGestureRecognizer类.手势识别UIGestureRecognizer类是个抽象类,下面的子类是具体的手势,开发这可以直接使用这些手势识别. UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecog
iOS 手势识别器概述
手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手势(UIRotationGestureRecognizer) 捏合手势( UIPinchGestureRecognizer) 长按手势( UILongPressGestureRecognizer) 平移手势( UIPanGestureRecognizer) 屏幕边缘平移手势(UIScreenEdge
iOS手势处理
iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UISwipeGestureRecognizer UIPanGestureRecognizer UILongPressGestureRecognizer 上面的手势对应的操作是: Tap (点一下) Pinch (二指往內或往外拨动,平时经常用到的缩放) 矩阵变换 Rot
iOS手势识别器
UIGestureRecognizer UIGestureRecognizer类,用于检测.识别用户使用设备时所用的手势.它是一个抽象类,定义了所有手势的基本行为.以下是UIGestureRecognizer子类,用于处理具体的用户手势行为: UITapGestureRecognizer // 1.单击 UILongPressGestureRecognizer // 3.长按 UISwipeGestureRecognizer // 4.轻扫 UIPanGestureRecognizer // 5
iOS 手势及触摸
转自:http://justsee.iteye.com/blog/1885538 一.响应链 在IOS开发中会遇到各种操作事件,通过程序可以对这些事件做出响应. 首先,当发生事件响应时,必须知道由谁来响应事件.在IOS中,由响应者链来对事件进行响应,所有事件响应的类都是UIResponder的子类, 响应者链是一个由不同对象组成的层次结构,其中的每个对象将依次获得响应事件消息的机会.当发生事件时,事件首先被发送给第一响应者,第一响应者往往是事 件发生的视图,也就是用户触摸屏幕的地方.事件将沿着响
iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作. UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(捏合) UIRotationGestureRecognizer(旋转) UITapGestureRecognizer(点按) UILo
IOS 手势事件的冲突
关于手操作需要强调几点: UIImageView默认是不支持交互的,也就是userInteractionEnabled=NO ,因此要接收触摸事件(手势识别),必须设置userInteractionEnabled=YES(在iOS中UILabel.UIImageView的userInteractionEnabled默认都是NO,UIButton.UITextField.UIScrollView.UITableView等默认都是YES). 轻扫手势虽然是连续手势但是它的操作事件只会在识别结束时调用