您的位置:首页 > 产品设计 > UI/UE

UI 手势 点击

2015-12-14 19:40 337 查看
//

//  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UI 手势 ui