2

我有两个 UIViewController 命名为ViewControllerA and ViewControllerB. ViewControllerA 是父类,ViewControllerB 是子类,它是[self.navigationController pushViewController:viewControllerB animated:YES];从 ViewControllerA 类中查看的。在 ViewControllerB 类中,我隐藏了 NavigationBar。在按钮操作中,我编码为来自 ViewControllerB 的 ViewControllerA [self.navigationController popViewControllerAnimated:YES];。现在,我想使用交换操作(滚动到上一个屏幕)而不是使用 UIButton 从 ViewControllerB 来 ViewControllerA。我怎样才能做到这一点?谁能给我任何建议或想法?提前致谢。

4

2 回答 2

2

您可以尝试UISwipeGestureRecognizer在您的子视图上使用执行[self.navigationController popViewControllerAnimated:YES];.

于 2012-01-25T07:25:06.660 回答
2

在子控制器中使用它

- (void)viewDidLoad 
{    
    UISwipeGestureRecognizer  *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release]; 
    [super viewDidLoad];
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
 {
    [self.navigationController popViewControllerAnimated:YES];
    NSLog(@"Swipe received.");
 }

根据需要使用方向..

快乐的编码...

于 2012-01-25T07:25:17.383 回答