ios 手势
// 一个手指长按,不停的转动摄像头
UILongPressGestureRecognizer *startPTZTurn_LongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(StartPTZTurnByLongPress:)];
startPTZTurn_LongPress.delegate = self;
[self.imagView addGestureRecognizer:startPTZTurn_LongPress];
// 一个手指单击,转一下动摄像头,然后停止转动
UITapGestureRecognizer *startPTZTurn_Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector
(StartPTZTurnByTap:)];
startPTZTurn_Tap.delegate = self;
[self.imagView addGestureRecognizer:startPTZTurn_Tap];
[startPTZTurn_LongPress requireGestureRecognizerToFail:startPTZTurn_Tap];
// 滑动,快速移动 如果云台始能,向上、下、左、右是转动摄像头方向的;否则只是移动到上个视频或下个视频
// 向右
UISwipeGestureRecognizer *movePTZVideo_right = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(movePTZTurnOrSwitchVideo_Right:)];
movePTZVideo_right.delegate = self;
movePTZVideo_right.direction = UISwipeGestureRecognizerDirectionRight;
[self.imagView addGestureRecognizer:movePTZVideo_right];
// 向左
UISwipeGestureRecognizer *movePTZVideo_left = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(movePTZTurnOrSwitchVideo_Left:)];
movePTZVideo_left.delegate = self;
movePTZVideo_left.direction = UISwipeGestureRecognizerDirectionLeft;
[self.imagView addGestureRecognizer:movePTZVideo_left];
// 向上
UISwipeGestureRecognizer *movePTZVideo_up = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector
(movePTZTurnOrSwitchVideo_Up:)];
movePTZVideo_up.delegate = self;
movePTZVideo_up.direction = UISwipeGestureRecognizerDirectionUp;
[self.imagView addGestureRecognizer:movePTZVideo_up];
// 向下
UISwipeGestureRecognizer *movePTZVideo_down = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(movePTZTurnOrSwitchVideo_down:)];
movePTZVideo_down.delegate = self;
movePTZVideo_down.direction = UISwipeGestureRecognizerDirectionDown;
[self.imagView addGestureRecognizer:movePTZVideo_down];
// 二指往内或者外
UIPinchGestureRecognizer *pictureZoom = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector
(pictureZoom:)];
pictureZoom.delegate = self;
[self.imagView addGestureRecognizer:pictureZoom];
self.imagView.userInteractionEnabled = YES;
self.imagView.multipleTouchEnabled = YES;
- (void)StartPTZTurnByTap:(UITapGestureRecognizer *)recognizer
{
m_gestureStartPoint = CGPointMake(0.0, 0.0);
m_gestureStartPoint = [recognizer locationInView:self];
TDirection direction;
if (m_bPTZAvailable && _playing)
{
TPUResourceInfo *pRes = videoController.videoRes;
if (!m_bPTZTurn_Start)
{
// 直接点击屏幕四个区域来控制区域
if (m_gestureStartPoint.x >= 0 && m_gestureStartPoint.x <= 80 &&
m_gestureStartPoint.y >= 150 && m_gestureStartPoint.y <= 350)
{
// 点所在区域(X:0-80, Y:150-350)
// 发送向左旋转命令
direction = Direction_Left;
}
else if (m_gestureStartPoint.x >= 240 && m_gestureStartPoint.x <= 320 &&
m_gestureStartPoint.y >= 150 && m_gestureStartPoint.y <= 350)
{
// 点所在区域(X:240-320, Y:150-350)
// 发送向右旋转命令
direction = Direction_Right;
}
else if (m_gestureStartPoint.x >= 100 && m_gestureStartPoint.x <= 220 &&
m_gestureStartPoint.y >= 0 && m_gestureStartPoint.y <= 200)
{
// 点所在区域(X:100-220, Y:0-130)
// 发送向上旋转命令
direction = Direction_Up;
}
else if (m_gestureStartPoint.x >= 100 && m_gestureStartPoint.x <= 220 &&
m_gestureStartPoint.y >= 250 && m_gestureStartPoint.y <= 450)
{
// 点所在区域(X:100-220, Y:250-450)
// 发送向下旋转命令
direction = Direction_Down;
}
int nRet = NDM_StartTurn(pRes, direction);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"-------------TAG_BTN_PTZ_DOWN nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
if (m_bPTZTurn_Start)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
}
}
- (void)StartPTZTurnByLongPress:(UILongPressGestureRecognizer *)recognizer
{
m_gestureStartPoint = CGPointMake(0.0, 0.0);
m_gestureStartPoint = [recognizer locationInView:self];
TDirection direction;
if (m_bPTZAvailable && _playing)
{
TPUResourceInfo *pRes = videoController.videoRes;
if (m_bPTZTurn_Start)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
else
{
// 直接点击屏幕四个区域来控制区域
if (m_gestureStartPoint.x >= 0 && m_gestureStartPoint.x <= 80 &&
m_gestureStartPoint.y >= 150 && m_gestureStartPoint.y <= 350)
{
// 点所在区域(X:0-80, Y:150-350)
// 发送向左旋转命令
direction = Direction_Left;
}
else if (m_gestureStartPoint.x >= 240 && m_gestureStartPoint.x <= 320 &&
m_gestureStartPoint.y >= 150 && m_gestureStartPoint.y <= 350)
{
// 点所在区域(X:240-320, Y:150-350)
// 发送向右旋转命令
direction = Direction_Right;
}
else if (m_gestureStartPoint.x >= 100 && m_gestureStartPoint.x <= 220 &&
m_gestureStartPoint.y >= 0 && m_gestureStartPoint.y <= 200)
{
// 点所在区域(X:100-220, Y:0-130)
// 发送向上旋转命令
direction = Direction_Up;
}
else if (m_gestureStartPoint.x >= 100 && m_gestureStartPoint.x <= 220 &&
m_gestureStartPoint.y >= 250 && m_gestureStartPoint.y <= 450)
{
// 点所在区域(X:100-220, Y:250-450)
// 发送向下旋转命令
direction = Direction_Down;
}
int nRet = NDM_StartTurn(pRes, direction);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"-------------TAG_BTN_PTZ_DOWN nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
}
}
- (void)movePTZTurnOrSwitchVideo_Up:(UISwipeGestureRecognizer *)recognizer {
TPUResourceInfo *pRes = videoController.videoRes;
if (m_bPTZAvailable && _playing) {
int nRet = NDM_StartTurn(pRes, Direction_Up);
if (nRet != NRCAPC_SUCCESS) {
NSLog(@"-------------TAG_BTN_PTZ_UP nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
if (m_bPTZTurn_Start) {
if (recognizer.state == UIGestureRecognizerStateEnded) {
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
}
- (void)movePTZTurnOrSwitchVideo_down:(UISwipeGestureRecognizer *)recognizer
{
TPUResourceInfo *pRes = videoController.videoRes;
if (m_bPTZAvailable && _playing)
{
int nRet = NDM_StartTurn(pRes, Direction_Down);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"-------------TAG_BTN_PTZ_DOWN nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
if (m_bPTZTurn_Start)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
}
- (void)movePTZTurnOrSwitchVideo_Left:(UISwipeGestureRecognizer *)recognizer
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (!m_bPTZAvailable && UIInterfaceOrientationIsPortrait(orientation))
{
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft && mPlayMode == REAL_PREVIEW)
{
_isdirection = ISD_RIGHT;
[self switchVideo:_isdirection];
}
}
TPUResourceInfo *pRes = videoController.videoRes;
if (m_bPTZAvailable && _playing)
{
int nRet = NDM_StartTurn(pRes, Direction_Left);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"-------------TAG_BTN_PTZ_LEFT nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
if (m_bPTZTurn_Start)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
}
- (void)movePTZTurnOrSwitchVideo_Right:(UISwipeGestureRecognizer *)recognizer
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (!m_bPTZAvailable && UIInterfaceOrientationIsPortrait(orientation))
{
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight && mPlayMode == REAL_PREVIEW)
{
_isdirection = ISD_LEFT;
[self switchVideo:_isdirection];
}
}
TPUResourceInfo *pRes = videoController.videoRes;
if (m_bPTZAvailable && _playing)
{
int nRet = NDM_StartTurn(pRes, Direction_Right);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"-------------TAG_BTN_PTZ_RIGHT nRet: 0x%08X", nRet);
}
m_bPTZTurn_Start = YES;
}
if (m_bPTZTurn_Start)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NDM_StopTurn(pRes);
m_bPTZTurn_Start = NO;
}
}
}
- (void)pictureZoom:(UIPinchGestureRecognizer *)recognizer
{
if (m_bPTZAvailable && _playing)
{
int nRet;
TPUResourceInfo *pRes = videoController.videoRes;
CGFloat scaleValue = [recognizer scale];
if (m_bPictureZoom)
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
// 发送停止图像缩放命令
nRet = NDM_StopPictureZoom(pRes);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"++++++++++++++++++++++++TAG_BTN_PictureZoom_*** stop. nRet: 0x%08X", nRet);
}
m_bPictureZoom = NO;
}
}
else
{
BOOL bZoomIn = FALSE;
if (scaleValue > 1)
{
bZoomIn = FALSE;
}
else
{
bZoomIn = TRUE;
}
// 发送缩小图像命令
nRet = NDM_StartPictureZoom(pRes, bZoomIn);
if (nRet != NRCAPC_SUCCESS)
{
NSLog(@"++++++++++++++++++++++++TAG_BTN_PictureZoom_SMALL nRet: 0x%08X", nRet);
}
m_bPictureZoom = YES;
}
}
}