Ios 滑动手势识别器可以';你没发现方向吗?
如果我使用这样的手势识别器Ios 滑动手势识别器可以';你没发现方向吗?,ios,objective-c,uigesturerecognizer,Ios,Objective C,Uigesturerecognizer,如果我使用这样的手势识别器 UISwipeGestureRecognizer *noRightShiftForVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)]; [self.circleProgressBar addGestureRecognizer:noRightShiftForVolume]; 因为我在视图控制器上有导航控
UISwipeGestureRecognizer *noRightShiftForVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)];
[self.circleProgressBar addGestureRecognizer:noRightShiftForVolume];
因为我在视图控制器上有导航控制器,所以这不会禁用视图上的滑动。
但是当我这样声明时,它工作正常,但不知道滑动的方向
UIPanGestureRecognizer *noRightShiftForVolume = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)];
[self.circleProgressBar addGestureRecognizer:noRightShiftForVolume];
该功能的实现如下:
- (void)handleVolumeViewSwipe1:(UISwipeGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan) {
[applicationControllerShared() enableSwipe:NO];
NSLog(@"good karens");
if(UISwipeGestureRecognizerDirectionLeft){
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[_circleProgressBar.layer addAnimation:animation forKey:kCATransition];
NSLog(@"Swipe Left");
}
if(UISwipeGestureRecognizerDirectionRight){
NSLog(@"Swipe Right");
}
}
if (sender.state == UIGestureRecognizerStateEnded)
{
[applicationControllerShared() enableSwipe:YES];
NSLog(@"good karens 110");
}
}
-(void) enableSwipe: (BOOL) state
{
eliminateSwipe = !state;
}
在导航控制器中
布尔消除器;
EliminateSweep函数如下所示:
- (void)handleVolumeViewSwipe1:(UISwipeGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan) {
[applicationControllerShared() enableSwipe:NO];
NSLog(@"good karens");
if(UISwipeGestureRecognizerDirectionLeft){
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[_circleProgressBar.layer addAnimation:animation forKey:kCATransition];
NSLog(@"Swipe Left");
}
if(UISwipeGestureRecognizerDirectionRight){
NSLog(@"Swipe Right");
}
}
if (sender.state == UIGestureRecognizerStateEnded)
{
[applicationControllerShared() enableSwipe:YES];
NSLog(@"good karens 110");
}
}
-(void) enableSwipe: (BOOL) state
{
eliminateSwipe = !state;
}
启用滑动功能禁用导航控制器滑动,并使我能够实现功能handleVolumeViewSwipe1。
我有一个圆圈进度条,我想检测左右滑动,并根据它执行功能。你知道我该怎么做吗
我曾尝试在ViewDidLoad和ViewDidAppear中实现此SwipGestureRecognitizerDirection,但由于导航控制器的滑动功能,对我无效
这是在UIPangestureRecognitor的帮助下解决的,可以通过以下代码检测到刷卡
if (sender.state == UIGestureRecognizerStateBegan) {
[applicationControllerShared() enableSwipe:NO];
CGPoint velocity = [sender velocityInView:_circleProgressBar];
if(velocity.x < 0)
{
NSLOG(@"swipe left");
}else{
NSLOG(@"swipe right");}
}
if(sender.state==UIgestureRecognitizerStateStart){
[applicationControllerShared()启用滑动:否];
CGPoint速度=[sender velocityInView:_circleProgressBar];
if(速度x<0)
{
NSLOG(@“向左滑动”);
}否则{
NSLOG(@“向右滑动”);}
}
根据我的经验,您需要应用UINavigationControllerDelegate
的委托来停止Pop手势
步骤1:确认.h文件中的协议。(可选步骤)
步骤3:在previos VC中禁用视图中的手势将消失。
(必选步骤)
希望这能对您有所帮助。您是否设置了手势的
noRightShiftForVolume.direction
属性?是的,但没有任何帮助。滑动“将我带到导航控制器OK”以便它将从该视图控制器弹出?是的,完全正确。您是否意识到如果(UISWEEgestureRecognitizerDirectionLeft){
没有比较任何东西?每个方向都需要一个单独的UISweepGestureRecognitor
。非常感谢你,但我已经应用了这个,它根本不起作用。你在哪里应用了它?在上一个屏幕或手势视图的同一屏幕中?我以前应用过,现在也尝试过。不起作用。我必须检测滑动方向。UITapperstation工作正常,但不知道为什么不使用UISweepGestureDirection不,我想问的是您在哪个屏幕上应用了上述代码?我在导航和viewController中都应用了,我需要滑动手势
self.navigationController.interactivePopGestureRecognizer.enabled = YES;