各种UIGestureRecognizer 手势

注:本文只为记录,没仔细讲解


#import "TouchViewController.h"


@interface TouchViewController ()


@end


@implementation TouchViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

    

    self.view.backgroundColor = [UIColorwhiteColor];

    

    UILabel *label = [[UILabelalloc]init];

    label.center = self.view.center;

    label.bounds = CGRectMake(0, 0, 150, 150);

    label.backgroundColor = [UIColororangeColor];

    label.alpha = 0.7;

    label.userInteractionEnabled =YES;

    [self.viewaddSubview:label];

    //点击手势

//    [self TapGestureRecognizer:label];

    //长按手势

//    [self LongPressGestureRecognizer:label];

    //轻扫手势

//    [self SwipeGestureRecognizer:label];

    //缩放手势

//    [self PinchGestureRecognizer:label];

    //拖动手势

//    [self PanGestureRecognizer:label];

    //旋转手势

    [selfRotationGestureRecognizer:label];

}


/**

 *  点击手势

 *  @param label 响应手势视图

 */

- (void)TapGestureRecognizer:(UILabel *)label{

    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(handleSingleFingerEvent:)];

    /**

     *  这两个可以随意匹配,可形成 单指双击||双指单击||双指双击等...

     */

    singleFingerOne.numberOfTouchesRequired = 2; //手指数

    singleFingerOne.numberOfTapsRequired = 2; //tap次数

    [label addGestureRecognizer:singleFingerOne];//给视图添加点击手势

}


/**

 *  点击手势执行的方法

 *  @param gestureRecognizer 传递点击手势

 */

- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)gestureRecognizer{

    NSLog(@"111 --- %f",gestureRecognizer.view.alpha);

}


/**

 *  长按手势

 *  @param label 响应手势视图

 */

- (void)LongPressGestureRecognizer:(UILabel *)label{

    //添加一个长按手势

    UILongPressGestureRecognizer *LPGR = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(LongPressGestureRecognizerFunction:)];

    LPGR.minimumPressDuration =1.0;//长按时间

    [label addGestureRecognizer:LPGR];

}


/**

 *  长按手势执行方法

 *  @param gestureRecognizer 传递长按手势

 */

- (void)LongPressGestureRecognizerFunction:(UILongPressGestureRecognizer *)gestureRecognizer{

    NSLog(@"111 --- %f",gestureRecognizer.view.alpha);

    /**

     *  如若不区分,则会执行两次

     */

    if (gestureRecognizer.state==UIGestureRecognizerStateBegan) {

        //开始状态

    }

    if(gestureRecognizer.state ==UIGestureRecognizerStateEnded){

        //结束状态

    }

}


/**

 *  轻扫手势

 *  @param label 响应手势视图

 */

- (void)SwipeGestureRecognizer:(UILabel *)label{

    UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(SwipeGestureRecognizerFunction:)];

    Swipe.numberOfTouchesRequired =2;//手指数

    [label addGestureRecognizer:Swipe];

}


/**

 *  轻扫手势响应方法

 *  @param GestureRecognizer 传递轻扫手势

 */

-(void)SwipeGestureRecognizerFunction:(UISwipeGestureRecognizer *)GestureRecognizer{

    NSLog(@"111 --- %f",GestureRecognizer.view.alpha);

    //指定轻扫手势响应的方向

    if (GestureRecognizer.direction==UISwipeGestureRecognizerDirectionLeft||UISwipeGestureRecognizerDirectionRight) {

        

    }

}


/**

 *  缩放手势

 *  @param label 响应手势视图

 */

- (void)PinchGestureRecognizer:(UILabel *)label{

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(PinchGestureRecognizerFunction:)];

    [label addGestureRecognizer:pinch];

    

}


/**

 *  缩放手势响应方法

 *  @param GestureRecognizer 传递缩放手势

 */

- (void)PinchGestureRecognizerFunction:(UIPinchGestureRecognizer *)GestureRecognizer{

    NSLog(@" --- %f --- %f",GestureRecognizer.scale,GestureRecognizer.velocity);

    CGRect  bounds = GestureRecognizer.view.bounds;

    bounds.size.height = bounds.size.height *GestureRecognizer.scale;

    bounds.size.width  = bounds.size.width  *GestureRecognizer.scale;

    GestureRecognizer.view.bounds = bounds;

}


/**

 *  拖动手势

 *  @param label 响应拖动手势的视图

 */

- (void)PanGestureRecognizer:(UILabel *)label{

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(PanGestureRecognizerFunction:)];

    panGesture.minimumNumberOfTouches =1;//最小需要的手指数

    panGesture.maximumNumberOfTouches =2;//最大需要的手指数

    [label addGestureRecognizer:panGesture];

}


/**

 *  拖动手势响应事件

 *  @param GestureRecognizer 传递拖动手势

 */

- (void)PanGestureRecognizerFunction:(UIPanGestureRecognizer *)GestureRecognizer{

    CGPoint translatedPoint = [GestureRecognizertranslationInView:self.view];

    CGFloat x = GestureRecognizer.view.center.x + translatedPoint.x;

    CGFloat y = GestureRecognizer.view.center.y + translatedPoint.y;

    GestureRecognizer.view.center =CGPointMake(x, y);

    [GestureRecognizer setTranslation:CGPointMake(0,0) inView:self.view];

    /**

     * 

     - (CGPoint)translationInView:(UIView *)view方法的API解释如下:

     

     The translation of the pan gesture in the coordinate system of the specified view.

     

     Return Value

     A point identifying the new location of a view in the coordinate system of its designated superview.

     字面理解是:

     在指定的视图坐标系统中转换(拖动?) pan gesture

     返回参数:返回一个明确的新的坐标位置,在指定的父视图坐标系统中

     简单的理解就是

     该方法返回在横坐标上、纵坐标上拖动了多少像素

     因为拖动起来一直是在递增,所以每次都要用setTranslation:方法制0这样才不至于不受控制般滑动出视图

     

     - (CGPoint)velocityInView:(UIView *)view方法的API解释如下:

     

     The velocity of the pan gesture in the coordinate system of the specified view.

     

     Return Value

     The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components.

     字面理解:

     在指定坐标系统中pan gesture拖动的速度

     返回参数:返回这种速度

     简单的理解就是

     你拖动这个图片的时候肯定有个速度,因此返回值就是你拖动时XY轴上的速度,速度是矢量,有方向。

     *

     */

}


/**

 *  旋转手势

 *  @param label 响应手势视图

 */

- (void)RotationGestureRecognizer:(UILabel *)label{

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

    rotation.rotation = 0;//旋转的弧度

    [label addGestureRecognizer:rotation];

}


/**

 *  旋转手势响应事件

 *  @param GestureRecognizer 传递响应的手势

 */

- (void)RotationGestureRecognizerFunction:(UIRotationGestureRecognizer *)GestureRecognizer{

    

    GestureRecognizer.view.transform =CGAffineTransformRotate(GestureRecognizer.view.transform, GestureRecognizer.rotation);

    GestureRecognizer.rotation = 0;

}



附:

typedef NS_ENUM(NSInteger, UIGestureRecognizerState) {

  UIGestureRecognizerStatePossible,  // 尚未识别是何种手势操作(但可能已经触发了触摸事件),默认状态

  UIGestureRecognizerStateBegan,   // 手势已经开始,此时已经被识别,但是这个过程中可能发生变化,手势操作尚未完成

  UIGestureRecognizerStateChanged,  // 手势状态发生转变

  UIGestureRecognizerStateEnded,   // 手势识别操作完成(此时已经松开手指)

  UIGestureRecognizerStateCancelled, // 手势被取消,恢复到默认状态

  UIGestureRecognizerStateFailed,   // 手势识别失败,恢复到默认状态

  UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded // 手势识别完成,同UIGestureRecognizerStateEnded

};




资源下载链接为: https://pan.quark.cn/s/3d8e22c21839 随着 Web UI 框架(如 EasyUI、JqueryUI、Ext、DWZ 等)的不断发展与成熟,系统界面的统一化设计逐渐成为可能,同时代码生成器也能够生成符合统一规范的界面。在这种背景下,“代码生成 + 手工合并”的半智能开发模式正逐渐成为新的开发趋势。通过代码生成器,单表数据模型以及一对多数据模型的增删改查功能可以被直接生成并投入使用,这能够有效节省大约 80% 的开发工作量,从而显著提升开发效率。 JEECG(J2EE Code Generation)是一款基于代码生成器的智能开发平台。它引领了一种全新的开发模式,即从在线编码(Online Coding)到代码生成器生成代码,再到手工合并(Merge)的智能开发流程。该平台能够帮助开发者解决 Java 项目中大约 90% 的重复性工作,让开发者可以将更多的精力集中在业务逻辑的实现上。它不仅能够快速提高开发效率,帮助公司节省大量的人力成本,同时也保持了开发的灵活性。 JEECG 的核心宗旨是:对于简单的功能,可以通过在线编码配置来实现;对于复杂的功能,则利用代码生成器生成代码后,再进行手工合并;对于复杂的流程业务,采用表单自定义的方式进行处理,而业务流程则通过工作流来实现,并且可以扩展出任务接口,供开发者编写具体的业务逻辑。通过这种方式,JEECG 实现了流程任务节点和任务接口的灵活配置,既保证了开发的高效性,又兼顾了项目的灵活性和可扩展性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值