gpt4 book ai didi

iphone - 设置SwipeGestureRecognizer进行uiview转换

转载 作者:行者123 更新时间:2023-12-01 17:44:12 26 4
gpt4 key购买 nike

我的UIView转换方法遇到了一些麻烦,该方法正在侦听屏幕上的手势。

发生的是,如果我进行向左滑动或向右滑动,则会向我的@selector方法发送左右滑动信号..这意味着我无法区分滑动。

这是我有问题的代码。我尝试了一些不同的操作,但似乎无法正确解决这一问题。

- (void) setupSwipeGestureRecognizer {
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen:)];
swipeGesture.direction = (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight);
[self.view addGestureRecognizer:swipeGesture];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Prototype";
//Initalizse the swipe gestuer listener
[self setupSwipeGestureRecognizer];

//alloc and init
self.detailViewA = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
self.detailViewB = [[DetailViewControllerB alloc]initWithNibName:@"DetailViewControllerB" bundle:[NSBundle mainBundle]];

// set detail View as first view
[self.view addSubview:self.detailViewA.view];

// set up other views
[self.detailViewB.view setAlpha:1.0f];

// Add the view controllers view as a subview
[self.view addSubview:self.detailViewB.view];

// set these views off screen (right)
[self.detailViewB.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];
}


- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture
{
if (gesture.direction = UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left");
}
if (gesture.direction = UISwipeGestureRecognizerDirectionRight){
NSLog(@"Right");
}

}

最佳答案

类似的问题herehere
swipedScreen:方法的参数类型为UISwipeGestureRecognizer,即导致调用回调的识别器。它不涉及用户做出的任何实际手势。在您的情况下,可以将此识别器的direction属性设置为(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)-这不会更改。

您将必须创建两个识别器,每个方向一个。

关于iphone - 设置SwipeGestureRecognizer进行uiview转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com