UI 手势 点击

//

//  RootViewController.m

//  UI 05 ___手势

//

//  Created by dllo on 15/12/14.

//  Copyright © 2015年 dllo. All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController ()

@property(nonatomic,retain)UIImageView *imageView;


@end


@implementation RootViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    self.view.backgroundColor=[UIColorwhiteColor];

    

    self.imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(100,100, 300, 300)];


    

    self.imageView.image=[UIImageimageNamed:@"65740fd8bc3eb1357c91e73da61ea8d3fc1f4464.jpg"];

    [self.viewaddSubview:self.imageView];

    

//    userInteractionEnabled叫用户交互。如果没打开的话没有办法通过手势方式和它进行交互

    

    

//    如果不确定交互开没开,打印一下就可以。,没打开的对象打印会有提示

    

    

    self.imageView.userInteractionEnabled=YES;

    

    

    NSLog(@"%@",self.imageView);

    [self.imageViewrelease];

    

//    

//


    

    

//    1。 点击

    UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapAction:)];

    


//   把手势添加到视图上去;

    

    

   [self.imageViewaddGestureRecognizer:tap];

//

//

//    内存管理

    

    [tap release];



//    触发方法需要点击几次,默认是1

    tap.numberOfTapsRequired=2;

    

    

    

    tap.numberOfTouchesRequired=2;

    

    


    UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPressAction:)];

    

    [self.imageViewaddGestureRecognizer:longPress];

    

    [longPress release];

    

//    设置触发的最短时间

    

    

    longPress.minimumPressDuration=2;

    

//    设置可移动的范围

    

    longPress.allowableMovement=300;

    

    

    


//    3.旋转手势

    

    UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotationAction:)];

    

    [self.imageViewaddGestureRecognizer:rotation];

    

    [rotation release];

    

    


    

    4,,,捏合

    

    UIPinchGestureRecognizer *PinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureActian:)];

    

    [self.imageView addGestureRecognizer:PinchGesture];

    


    [PinchGesture release];

    

    

    

    

    拖拽

    

    UIPanGestureRecognizer *uipan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(uipanAc:)];

    

    

    [self.imageView addGestureRecognizer:uipan];

    [uipan release];

    

    

    

    6.轻扫手势

    

    UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];

    [self.imageViewaddGestureRecognizer:swipe];

    [swipe release];

    

    

    

    

    7 . 屏幕边界手势

    

    这个手势出现的最晚,7.0以后才出现

   UIScreenEdgePanGestureRecognizer

    

    

    

    给视图添加一个毛玻璃效果

    

    UIBlurEffect *effect=[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];

    UIVisualEffectView*view=[[UIVisualEffectView alloc]initWithEffect:effect];

    view.alpha=0.4;

    

    view.frame=CGRectMake(0,0, 300, 300);

    [self.imageViewaddSubview:view];

    

    

    [view release];

    

    self.view.backgroundColor=[UIColorwhiteColor];

    

    

//    响应者链

    

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];

    [self.imageViewaddGestureRecognizer:tap];

    [tap release];

    

    UIButton *buttonFirst=[UIButtonbuttonWithType:UIButtonTypeSystem];

    

    buttonFirst.frame=CGRectMake(0,0, 100, 100);

    

    buttonFirst.backgroundColor=[UIColorredColor];

    

    [self.imageViewaddSubview:buttonFirst];

    

    [buttonFirst addTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];

    

    

    UIButton *buttonSec=[UIButtonbuttonWithType:UIButtonTypeSystem];

    

    buttonSec.frame=CGRectMake(100,250, 100, 100);

    

    buttonSec.backgroundColor=[UIColororangeColor];

    

    [self.imageViewaddSubview:buttonSec];

    

    [buttonSec addTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];

    

    

    

    

    

    

    

    

    

    

    

}


//

//轻点的点击方法

//

//-(void)tapAction:(UITapGestureRecognizer *)tap{

//

//

//

//    NSLog(@"点击了");

//

//

//}

//



//

//-(void)longPressAction:(UILongPressGestureRecognizer *)longPress{

//

//    NSLog(@"长按了");

    可以按照对应的手势状态来完成判断

//    

//    if (longPress.state==UIGestureRecognizerStateBegan) {

//        NSLog( @"开始了");


//}

//}


//旋转手势


-(void)rotationAction:(UIRotationGestureRecognizer *)rotation{


    NSLog(@"转起来");


    //图片随手势一同旋转

    self.imageView.transform=CGAffineTransformRotate(self.imageView.transform, rotation.rotation);

    rotation.rotation=0;

    

    NSLog(@"%g",rotation.rotation);

}

//

//


-(void)PinchGestureAction:(UIPinchGestureRecognizer   *)PinchGesture{


//

//

    NSLog(@"捏合");


    self.imageView.transform=CGAffineTransformScale(self.imageView.transform, pinch.scale,pinch.scale);

    

    pinch.scale=1;



//}





-(void)uipanAc:(UIPanGestureRecognizer *)uipan{

    NSLog(@"拖拽");

    

//    先根据手势找到经过的点

   CGPoint p= [uipan translationInView:self.imageView];

//   修改视图的transform

//

    self.imageView.transform=CGAffineTransformTranslate(self.imageView.transform, p.x, p.y);

    [uipan setTranslation:CGPointZero inView:self.imageView];

}





-(void)swipeAction:(UISwipeGestureRecognizer *)swipe{

    NSLog(@"轻扫");


}


//

//

//


-(void)tap:(UITapGestureRecognizer *)tap{

    NSLog(@"图片被点击了");


}



-(void)click:(UIButton *)button{



    NSLog(@"button被电击了");



}












-(void)dealloc{

    [_imageView release];

    [super release];


}






- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值