//先建一个视图图片
UIImageView
*image1 =[[
UIImageView
alloc
]
initWithFrame
:
CGRectMake
(
30
,
30
,
300
,
300
)];
image1.
image
=[
UIImage
imageNamed
:
@“12"
];
image1.
center
=
self
.
view
.
center
;
[ self . view addSubview :image1];
[image1 release ];
[ self . view addSubview :image1];
[image1 release ];
//
//打开交互
image1.userInteractionEnabled =YES;
/*************
轻拍
****************/
UITapGestureRecognizer
*tap =[[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(tapAction:)];
// 点击次数
tap. numberOfTapsRequired = 2 ;
// 手指个数
tap. numberOfTouchesRequired = 2 ;
[image1 addGestureRecognizer :tap];
// 点击次数
tap. numberOfTapsRequired = 2 ;
// 手指个数
tap. numberOfTouchesRequired = 2 ;
[image1 addGestureRecognizer :tap];
[tap release];
/*************
轻拍方法
************/
- ( void )tapAction:( UITapGestureRecognizer *)tap{
NSLog ( @" 轻拍 " );
}
/*************
轻扫
******************/
UISwipeGestureRecognizer *swipe =[[ UISwipeGestureRecognizer alloc ] initWithTarget : self action : @selector (swipeAction:)];
//
默认向右扫
// 方向只能正方向 , 不能斜着扫
// 只能上下一起
// 方向只能正方向 , 不能斜着扫
// 只能上下一起
//或者左右一起
swipe.
direction
=swipe.
direction
=
UISwipeGestureRecognizerDirectionRight
|
UISwipeGestureRecognizerDirectionLeft
;
[image1 addGestureRecognizer :swipe];
[image1 addGestureRecognizer :swipe];
[swipe release];
//或是 | ,就是一个|
/*************
轻扫方法
swipe
************/
- (
void
)swipeAction:(
UISwipeGestureRecognizer
*)swipe
{
if (swipe. direction == UISwipeGestureRecognizerDirectionLeft ) {
NSLog ( @" 向左 " );
}
NSLog ( @" 轻扫 " );
{
if (swipe. direction == UISwipeGestureRecognizerDirectionLeft ) {
NSLog ( @" 向左 " );
}
NSLog ( @" 轻扫 " );
}
/*************
捏合
pinch *****************/
UIPinchGestureRecognizer
*pinch = [[
UIPinchGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(pinchAction:)];
[image1 addGestureRecognizer :pinch];
[image1 addGestureRecognizer :pinch];
[pinch release];
/*************
捏合
pinch方法 **************/
- (
void
)pinchAction:(
UIPinchGestureRecognizer
*)pin
{
{
NSLog
(
@"
捏合
"
);
// 捏合时 等比例缩放图片
UIImageView *image1 = ( UIImageView *)pin. view ;
// 设置比例
// scale 比例
// 参数 1: 要缩放的视图的 transform
// 参数 2: 横向比例
// 捏合时 等比例缩放图片
UIImageView *image1 = ( UIImageView *)pin. view ;
// 设置比例
// scale 比例
// 参数 1: 要缩放的视图的 transform
// 参数 2: 横向比例
// 参数3: 纵向比例
// scale:
相对接触点的缩放比例在屏幕协调
[image1
setTransform
:
CGAffineTransformScale
(image1.
transform
, pin.
scale
, pin.
scale
)];
//
缩放结束之后
,
将缩放比例设置为
1
pin.scale = 1;
}
/*************
旋转
rotation ***********/
#if
0
{
UIRotationGestureRecognizer *rotation = [[ UIRotationGestureRecognizer alloc ] initWithTarget : self action : @selector (rotationAction:)];
[image1 addGestureRecognizer :rotation];
[rotation release ];
}
{
UIRotationGestureRecognizer *rotation = [[ UIRotationGestureRecognizer alloc ] initWithTarget : self action : @selector (rotationAction:)];
[image1 addGestureRecognizer :rotation];
[rotation release ];
}
#endif
/*************
旋转
rotation ************/
- (
void
)rotationAction:(
UIRotationGestureRecognizer
*)rot
{
NSLog ( @" 旋转 ~ 跳跃 ~" );
// 获取旋转手势时 让图片跟随旋转
// 1. 获取图片对象
UIImageView *image1 = ( UIImageView *)rot. view ;
// 2. 设置视图的 transform 属性
// transform 视图的变形属性
[image1 setTransform : CGAffineTransformMakeRotation (rot. rotation )];
NSLog ( @"%@" , image1);
}
{
NSLog ( @" 旋转 ~ 跳跃 ~" );
// 获取旋转手势时 让图片跟随旋转
// 1. 获取图片对象
UIImageView *image1 = ( UIImageView *)rot. view ;
// 2. 设置视图的 transform 属性
// transform 视图的变形属性
[image1 setTransform : CGAffineTransformMakeRotation (rot. rotation )];
NSLog ( @"%@" , image1);
}
#if
0
/*************
拖拽
pan *********/
{
UIPanGestureRecognizer *pan = [[ UIPanGestureRecognizer alloc ] initWithTarget : self action : @selector (panAction:)];
[image1 addGestureRecognizer :pan];
[pan release ];
}
UIPanGestureRecognizer *pan = [[ UIPanGestureRecognizer alloc ] initWithTarget : self action : @selector (panAction:)];
[image1 addGestureRecognizer :pan];
[pan release ];
}
#endif
/************** pan
拖拽
****************/
- (
void
)panAction:(
UIPanGestureRecognizer
*)pan
{
NSLog ( @" 拖拽 " );
// 拖拽视图
UIImageView *panView = ( UIImageView *)pan. view ;
// 获取拖拽时 经过的点
CGPoint p = [pan translationInView :panView];
// 设置 transform
[panView setTransform : CGAffineTransformTranslate (panView. transform , p. x , p. y )];
// 设置跟随属性
[pan setTranslation : CGPointZero inView :panView];
{
NSLog ( @" 拖拽 " );
// 拖拽视图
UIImageView *panView = ( UIImageView *)pan. view ;
// 获取拖拽时 经过的点
CGPoint p = [pan translationInView :panView];
// 设置 transform
[panView setTransform : CGAffineTransformTranslate (panView. transform , p. x , p. y )];
// 设置跟随属性
[pan setTranslation : CGPointZero inView :panView];
}
#if
0
/**********
长按
longPress***********/
{
UILongPressGestureRecognizer *longPress = [[ UILongPressGestureRecognizer alloc ] initWithTarget : self action : @selector (longPressAction:)];
// 需要多长时间触发
longPress. minimumPressDuration = 2 ;
// 允许移动的距离
longPress. allowableMovement = 200 ;
// 添加
[image1 addGestureRecognizer :longPress];
[longPress release ];
}
UILongPressGestureRecognizer *longPress = [[ UILongPressGestureRecognizer alloc ] initWithTarget : self action : @selector (longPressAction:)];
// 需要多长时间触发
longPress. minimumPressDuration = 2 ;
// 允许移动的距离
longPress. allowableMovement = 200 ;
// 添加
[image1 addGestureRecognizer :longPress];
[longPress release ];
}
#endif
/********
长按
longPress ******************/
- (
void
)longPressAction:(
UILongPressGestureRecognizer
*)longPress
{
// 其他手势也可以触发长按 可以通过状态来判断
//UIGestureRecognizerStateBegan 姿态识别器状态开始了
if (longPress. state == UIGestureRecognizerStateBegan ) {
NSLog ( @" 长按 " );
}
{
// 其他手势也可以触发长按 可以通过状态来判断
//UIGestureRecognizerStateBegan 姿态识别器状态开始了
if (longPress. state == UIGestureRecognizerStateBegan ) {
NSLog ( @" 长按 " );
}
}