UI 06 of 7 gestures

Source: Internet
Author: User

// UIImageView    UIImage *image = [UIImage imageNamed:@"u=3179572108,1349777253&fm=21&gp=0.jpg"];    self.imageView = [[UIImageView alloc] initWithImage:image];    self.imageView.frame = CGRectMake(45100300300);    [self.view addSubview:self.imageView];    [_imageView release];
1. Click
    //user interaction By default is only two controls, one is not able to click on the Uilabel, and one is uiimageview. We want to click Uiimageview to open the user interaction.     Self. ImageView. userinteractionenabled=YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] Initwithtarget: SelfAction@selector(tapaction:)];//Set how many clicks will trigger the method:Tap. numberoftapsrequired=2;//Set several fingers:Tap. numberoftouchesrequired=2;//Add gestures to the corresponding picture[ Self. ImageViewADDGESTURERECOGNIZER:TAP]; [Tap release];
#pragma mark 点击的手势方法.- (void)tapAction:(UITapGestureRecognizer *)tap{    // 点击改变图片    self.imageView.image = [UIImage imageNamed:@"1.jpg"];}
2. Long Press
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizerinitWithTarget:selfaction:@selector(longPressAction:)];    // 设置长按触发的最小时间    1;    // 允许用户手指在长安过程中允许移动的距离,超过范围就停止.    200;    // 把手势添加到图片    [selfaddGestureRecognizer:longPress];    [longPress release];
#pragma Mark's long-pressed gesture method.- (void) Longpressaction: (Uilongpressgesturerecognizer *) longpress{//Long Press status   //longpress.state;    //Long press to eject a uialertview    if( Self. Alertview==Nil) { Self. Alertview= [[Uialertview alloc] initwithtitle:@"Do you want to delete it?"message:@"Don't delete me!"Delegate Selfcancelbuttontitle:@"sell Moe shameful, ruthlessly delete!"otherbuttontitles:@"You're so cute, don't delete it ~",Nil]; [ Self. AlertviewShow];    [_alertview release]; }Else{       [ Self. AlertviewShow]; }}
3. Rotate
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizerinitWithTarget:selfaction:@selector(rotationAction:)];    [selfaddGestureRecognizer:rotation];    [rotation release];
#pragma mark rotates the picture by rotating the gesture.- (void) Rotationaction: (Uirotationgesturerecognizer *) rotation{//The view that can be added by gesture capture gesture    Uiimageview*imageview = (Uiimageview*) rotation. View;NSLog(@"%@", ImageView);//rotation Operation    //Use a transform property of the view to rotate the view.//Imageview.transform = Cgaffinetransformmakerotation (rotation.rotation);ImageView. Transform= Cgaffinetransformrotate (ImageView. Transform, rotation. Rotation); Rotation. Rotation=0;}
4. Kneading
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizerinitWithTarget:selfaction:@selector(pinchAction:)];    [selfaddGestureRecognizer:pinch];    [pinch release];
#pragma mark 通过捏合手势,等比例缩放图片.- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{    // 通过手势找视图    UIImageView *imageview = (UIImageView *)pinch.view;    // 通过Transform 改变图片尺寸    imageview.transform = CGAffineTransformScale(imageview.transform, pinch.scale, pinch.scale);    pinch.scale1;// 给它终止的一个尺寸,不让照片直接消失.=}
5. Dragging
uipangesturerecognizer *pan = [[Uipangesturerecognizer Alloc] Initwithtarget:self  action: @selector  (    Panaction:)]; [self  .imageview  Addgesturerecognizer:pan];    //gesture requires a direction to be specified.  //right stroke  swipe.direction  = uiswipegesturerecognizerdirectionright;  
#pragma mark 拖拽手势,让图片随着手势移动而移动.- (void)panAction:(UIPanGestureRecognizer *)pan{   // 通过手势找视图    UIImageView *imageview = (UIImageView *)pan.view;    //通过手势获得经过的点.   CGPoint p = [pan translationInView:imageview];    // 设置移动的位置   imageview.transform = CGAffineTransformTranslate(imageview.transform, p.x, p.y);    //为了防止手势在操作的时候视图消失.    [pan setTranslation:CGPointZero inView:imageview];}
6. Swipe
 uiswipegesturerecognizer  * swipe = [[uiswipegesturerecognizer  alloc]  Initwithtarget:  self  action:   @selector  (swipeaction: )];    [self . ImageView addgesturerecognizer:  swipe]; [Swipe release];  
#pragma  mark 轻扫手势- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{    if (swipe.direction == UISwipeGestureRecognizerDirectionRight ) {        NSLog(@"xiangyou");//需要把拖拽移除.    }}
7. Screen margin gestures, gestures that appear after iOS7.0.
UIScreenEdgePanGestureRecognizer *screenEdge = [[UIScreenEdgePanGestureRecognizerinitWithTarget:selfaction:@selector(screenEdgeAction:)];    [selfaddGestureRecognizer:screenEdge     ];    [screenEdge release];

The corresponding method has not been added yet!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UI 06 of 7 gestures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.