XMG 各种手势

2024-06-24 10:48
文章标签 xmg 手势

本文主要是介绍XMG 各种手势,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.

- (void)setUpTap

{

    // 创建点按手势

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

    tap.numberOfTapsRequired=2;

    tap.delegate = self;

    

    [_imageView addGestureRecognizer:tap];

}


- (void)tap:(UITapGestureRecognizer *)tap

{

    NSLog(@"%s",__func__);

}



2.手势的代理

//是否允许触发手势

//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer


//是否支持多指,默认不支持

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer




现在允许接收手指的触摸点。比如我下面控制的是左边不响应右边相应

//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{



*)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

//    // 获取当前的触摸点

//    CGPoint curP = [touch locationInView:self.imageView];

//    

//    if (curP.x < self.imageView.bounds.size.width * 0.5) {

//        return NO;

//    }else{

//        return YES;

//    }

//}


2.长按手势

UILongPressGestureRecognizer

// 默认会触发两次

- (void)setUpLongPress

{

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

    

    [self.imageView addGestureRecognizer:longPress];

}



- (void)longPress:(UILongPressGestureRecognizer *)longPress

{

    

    if (longPress.state == UIGestureRecognizerStateBegan) {

        

        NSLog(@"%s",__func__);

    }

}


3.UISwiperGesture

横扫手势分方向  。默认一个控件只支持一种方向

如果想让一个控件支持多个方向的需要添加多个横扫手势

// 默认轻扫的方向是往右

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

    

    swipe.direction = UISwipeGestureRecognizerDirectionUp;

    

    [self.imageView addGestureRecognizer:swipe];

    

    // 如果以后想要一个控件支持多个方向的轻扫,必须创建多个轻扫手势,一个轻扫手势只支持一个方向

    // 默认轻扫的方向是往右

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

    

    swipeDown.direction = UISwipeGestureRecognizerDirectionDown;

    

    [self.imageView addGestureRecognizer:swipeDown];


4、option+shift可以把两个手指往上面移动

5.  旋转手势

#pragma mark - 旋转手势

- (void)setUpRotation

{

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];

    rotation.delegate = self;

    [self.imageView addGestureRecognizer:rotation];

}


// 默认传递的旋转的角度都是相对于最开始的位置

- (void)rotation:(UIRotationGestureRecognizer *)rotation

{

    

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

    

    // 复位

    rotation.rotation = 0;

    

    // 获取手势旋转的角度

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

}

6.

捏合手势(也就是缩放手势)

- (void)setUpPinch

{

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

    pinch.delegate = self;

    [self.imageView addGestureRecognizer:pinch];

}


- (void)pinch:(UIPinchGestureRecognizer *)pinch

{

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

    

    // 复位

    

    pinch.scale = 1;

}

7.

拖拽手势


#pragma mark - 拖拽

- (void)setUpPan

{

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

    

    

    [self.imageView addGestureRecognizer:pan];

}


- (void)pan:(UIPanGestureRecognizer *)pan

{

    // 获取手势的触摸点

   // CGPoint curP = [pan locationInView:self.imageView];

    

    // 移动视图

    // 获取手势的移动,也是相对于最开始的位置

    CGPoint transP = [pan translationInView:self.imageView];

    

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

    

    // 复位

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

    

  //  NSLog(@"%@",NSStringFromCGPoint(curP));

}














这篇关于XMG 各种手势的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1089935

相关文章

XMG 绘制形状

1. 除非是绘制曲线直接使用原生的。如果绘制形状直接使用UIBezerPath  2. 命名原则,类方法以类名开头 UIBezierPath bezierPathWithRect 3.圆角半径 画圆的大小 以每个顶点为圆心。给定的半径为半径画一个1/4圆。把周边的给切掉 4.只有封闭的形状调用这个方法才有用 [path fill] 5. stroke 描边一下

XMG Quartz2D的简单使用

// //  Quratz2DView.m //  Quartz2D // //  Created by 王宁 on 16/5/6. //  Copyright © 2016年 ylshmacmini. All rights reserved. // #import "Quratz2DView.h" //Quartz@2D是一个二维绘图引擎,同时支

XMG 自动提示宏 #define keyPath(objc,keyPath) @(((void)objc.keyPath,#keyPath));

1. int a=((void)5,4)  C语言逗号表达式默认会取右边的内容 如果不写void的话 a会被报警告,写上void标明请忽略左边的内容 插曲刚才弄得,已经上线的苹果产品如果需要下架的话,点击 价格与销售范围,然后点击下架。这个产品就会在AppStore 中移除。如果想再让改产品重新在Apple store中显示,那么再次让他上线就可以了。但是会有一定的时间延迟 /

XMG 抽屉效果

1.比如说我创建了3个View -(void)viewDidLoad{  [ super viewDidLoad]; [self setUpChild] ;         UIPanGestureRecognizer *pan=[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];

XMG 常用的手势

// 创建点按手势     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];    tap.numberOfTabsRequired=2; //点击的次数

XMG 触摸事件的处理过程

1.自己本身并不处理,顺着响应者链条向上传递,将事件交给响应者进行处理 2.touches默认做法:把事件传递到上一个响应者 3. super是父类不是父控件

XMG 重写- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法

//重写这个方法,来完成一些指定的事件。比如说按钮被遮到下面了,但是我想让点击到这块区域的时候让按钮去相应点击 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {     // 当前坐标系上的点转换到按钮上的点     CGPoint btnP = [self convertPoint:point toVi

XMG xib中不属于一个类的控件,拖线到指定的类中

1.比如我现在有一个view绑定为GreenView,我们按住control向类里面拖线的方式想要达到目的,显然拖不进去。例图如下 那么我们此时还想要达到目的,就需要自己去GreenView的类内部去写IBo 然后这面连接起来 2.第二,大哥郝良建给做的扩展 可以在.h或者.m中写一个NSObject的属性 然后在xib中对应的位置创建一个NSObject的属性

iOS Runloop面试题(解释一下 手势识别 的过程?)

解释一下 手势识别 的过程? 当上面的 _UIApplicationHandleEventQueue()识别了一个手势时,其首先会调用 Cancel 将当前的 touchesBegin/Move/End 系列回调打断。随后系统将对应的 UIGestureRecognizer 标记为待处理。 苹果注册了一个 Observer 监测 BeforeWaiting (Loop即将进入休眠) 事件,这个

编写 Android 触摸屏手势识别程序

很多时候,利用触摸屏的Fling、Scroll等Gesture(手势)操作来操作会使得应用程序的用户体验大大提升,比如用Scroll手势在 浏览器中滚屏,用Fling在阅读器中翻页等。在Android系统中,手势的识别是通过 GestureDetector.OnGestureListener接口来实现的,不过William翻遍了Android的官方文档也没有找到一个相 关的例子,API Demo