- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *) gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *)otherGestureRecognizer;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; // 设置代理 tap.delegate = self; // 设置点击次数触发手势事件 tap.numberOfTapsRequired = 1; // 设置需要点击的手指数 tap.numberOfTouchesRequired = 1; [self.image addGestureRecognizer:tap];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; // 代理 longPress.delegate = self; // 设置最小间隔时间, 手指按下与离开间隔时间 longPress.minimumPressDuration = 1.0; // 按下过程中允许移动的像素 longPress.allowableMovement = 30; [self.image addGestureRecognizer:longPress];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)]; // 代理 pinch.delegate = self; // 设置缩放比例 pinch.scale = 1.2; [self.image addGestureRecognizer:pinch];
- (void)setupRotation
{
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
// 设置代理
rotation.delegate = self;
[self.image addGestureRecognizer:rotation];
}
- (void)rotation:(UIRotationGestureRecognizer *)rotation
{
// 旋转角度
CGFloat radian = rotation.rotation;
self.image.transform = CGAffineTransformRotate(self.image.transform, radian);
// 复位,保证每次都是在上一次位置开始转,而不是每次都回归初始位置再转
rotation.rotation = 0;
}
typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
UISwipeGestureRecognizerDirectionRight = 1 << 0, // 从左向右
UISwipeGestureRecognizerDirectionLeft = 1 << 1, // 从右向左
UISwipeGestureRecognizerDirectionUp = 1 << 2, // 从下往上
UISwipeGestureRecognizerDirectionDown = 1 << 3 // 从上往下
};
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; // 设置代理 swipeUp.delegate = self; // 修改方向, 从下往上 swipeUp.direction = UISwipeGestureRecognizerDirectionUp; [self.image addGestureRecognizer:swipeUp]; // 添加其他方向手势 UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; // 修改方向, 从下往上 swipeDown.direction = UISwipeGestureRecognizerDirectionDown; [self.image addGestureRecognizer:swipeDown];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; // 设置代理 pan.delegate = self; [self.image addGestureRecognizer:pan];
// 手势的触摸点 // CGPoint p = [pan locationInView:self.image]; // 手势的移动点(每次移动的位移点) CGPoint transP = [pan translationInView:self.image]; NSLog(@"%f, %f", transP.x, transP.y); self.image.transform = CGAffineTransformTranslate(self.image.transform, transP.x, transP.y); // 复位 [pan setTranslation:CGPointZero inView:self.image];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有