嗨,我有一个关于 UISwipeGestureRecognizer 的问题。下面是刷卡的代码,它工作正常,但不是我想要的那样。我的 onPlay 动作包含一个 if 语句,我希望 swipeUp 手势仅适用于其中一个 if 语句,而 swipeDown 则适用于 if 语句的另一种情况。即向上滑动以启动动画并向下滑动以停止它有什么方法可以工作吗?我会非常寻求帮助。
UISwipeGestureRecognizer *swipeUp =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onPlay)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
[swipeUp release];
UISwipeGestureRecognizer *swipeDown =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onPlay)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeDown];
[swipeDown release];
编辑:
-(IBAction)onPlay:(BOOL)isServer
{
[btnPlay setTitle:@"PLAY" forState:UIControlStateNormal];
if (isServer)
{
[btnPlay setHidden:false];
[btnOpen setHidden:false];
[btnSend setHidden:false];
[lblConnectedPeers setHidden:false];
[lblConnectedPeersCnt setHidden:false];
[m_communication SetConnectionMode:SERVER_CONNECTION];
m_isServer = true;
[m_pPlayer SetType:SERVER];
}
else {
[btnPlay setHidden:true];
[btnOpen setHidden:true];
[btnSend setHidden:true];
[lblConnectedPeers setHidden:true];
[lblConnectedPeersCnt setHidden:true];
[m_communication SetConnectionMode:CLIENT_CONNECTION];
[m_communication StartPeer];
m_isServer = false;
[m_pPlayer SetType:CLIENT];
}
[self ShowConnectionInfo:nil];
}