IOS Gesture手势(点击、捏合、滑动、长按、旋转、拖动)

ViewController.h

//
//  ViewController.h
//  GestureTest
//
//  Created by admin on 14-4-9.
//  Copyright (c) 2014年 TESTC600. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@property (strong, nonatomic) IBOutlet UILabel *labShowInfo;
@property (strong, nonatomic) IBOutlet UIImageView *imgshow;

- (IBAction)actionTapGesturn:(id)sender;

@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *swipeGesturn;
- (IBAction)actionSwipeGesturn:(id)sender;

@property (strong, nonatomic) IBOutlet UILabel *labback;


@property (strong, nonatomic) IBOutlet UIPinchGestureRecognizer *pinchGesturn;
@property(nonatomic, unsafe_unretained)CGFloat currentScale;
- (IBAction)actionPinch:(id)sender;

 

//rotation
@property (strong, nonatomic) IBOutlet UIRotationGestureRecognizer *rotationGesturn;
- (IBAction)actionRotation:(id)sender;
@property (nonatomic,unsafe_unretained)CGFloat rotationAngleInRadians; 


//long press
- (IBAction)longpressGesturn:(id)sender;

//pin
@property (strong, nonatomic) IBOutlet UIPanGestureRecognizer *pinGest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现手势识别并根据不同的手势控制图像旋转,你可以使用OpenCV和一些计算几何的知识。下面是一个示例代码,可以检测向右滑动和向左滑动手势,并相应地旋转图像。 ```python import cv2 import numpy as np # 使用摄像头捕获视频帧 cap = cv2.VideoCapture(0) # 初始化变量 start_point = None end_point = None while True: # 读取视频帧 ret, frame = cap.read() # 镜像翻转帧 frame = cv2.flip(frame, 1) # 将帧转换为灰度图像 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 进行手势识别(这里需要根据你选择的手势识别方法进行相应的代码编写) # 例如,使用背景减除法来提取手的轮廓 # ... # 根据手势控制图像旋转 if start_point is not None and end_point is not None: # 计算手势滑动的方向和距离 dx = end_point[0] - start_point[0] dy = end_point[1] - start_point[1] # 根据滑动方向进行图像旋转 if dx > 50: # 向右滑动 frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE) elif dx < -50: # 向左滑动 frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE) # 显示处理后的图像 cv2.imshow('Gesture Recognition', frame) # 按下'q'键退出循环 if cv2.waitKey(1) & 0xFF == ord('q'): break # 处理鼠标事件 def mouse_callback(event, x, y, flags, param): nonlocal start_point, end_point if event == cv2.EVENT_LBUTTONDOWN: start_point = (x, y) elif event == cv2.EVENT_LBUTTONUP: end_point = (x, y) # 注册鼠标回调函数 cv2.setMouseCallback('Gesture Recognition', mouse_callback) # 释放摄像头并关闭窗口 cap.release() cv2.destroyAllWindows() ``` 在上述代码中,我们使用了鼠标事件来模拟手势滑动。当鼠标按下时,记录起始点的坐标,当鼠标释放时,记录结束点的坐标。然后根据起始点和结束点的坐标计算滑动的方向和距离,并根据不同的方向旋转图像。请注意,这只是一个示例代码,你需要根据你选择的手势识别方法进行相应的代码编写。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值