如何在 iPhone SDK 中通过滑动来推送/弹出控制器?

发布于 2024-12-03 02:56:22 字数 422 浏览 1 评论 0原文

目前我正在开发一个 iPhone 应用程序,其中通过滑动手势识别器在两个控件之间导航。

应用程序结构是这样的 在此处输入图像描述

为此,我首先加载日历屏幕,在它的视图上加载,我加载主页使用 PushViewController 进行屏幕显示。在主屏幕上,如果用户向左滑动,则使用 PopViewController 显示日历屏幕,或者如果用户向右滑动,则使用 PushViewController 显示列表视图屏幕。这工作正常。

现在的问题是,在我的列表视图屏幕上,我使用 UITableViewController,其中手势识别器无法正常工作,有时它无法滑动。

我怎样才能完美地在这些屏幕之间滑动,我想像滚动视图滚动一样滑动。

请给我一些解决方案。

Currently i am developing an iPhone application in which navigation between two controls by swipe gesture recognizer.

Applicaiton structure is like this enter image description here

For this i first load calendar screen and on it's view did load, i load home screen by using PushViewController. On home screen if user swipe's his left then calendar screen shows using PopViewController or if user swipe's his right then listview screen shows by PushViewController. This is working fine.

Now problem is that on my listview screen i am using a UITableViewController where Gesture Recognizer will not working perfectly, some time it cannot swipe.

How can i swipe between these screen perfectly, I want to swipe same as scrollview scrolling.

Please provide me some solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏雨一样淡蓝的深情 2024-12-10 02:56:22

如果您的应用程序运行在 iOS 3.2 或更高版本上,您可以使用 UISwipeGestureRecognizer 执行此操作,如下所示。

//Add Table
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    table.dataSource=self;
    table.delegate=self;
    [table reloadData];
    [self.view addSubview:table];
    [table release];

    //Add Gesture Recognizer
    swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)];
    [table addGestureRecognizer:swipeLeftRecognizer];
    [swipeLeftRecognizer release];

在你的控制器的某个地方;

-(void)handleSwipeFrom {

    if (swipeLeftRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {

        // Your code here to go back to the main view

    }

}

这只会对向右滑动做出反应,并且会让您的表格以正常方式运行。希望这有帮助! :)

Provided your app is on iOS 3.2 or above, you can do this with a UISwipeGestureRecognizer as follows.

//Add Table
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    table.dataSource=self;
    table.delegate=self;
    [table reloadData];
    [self.view addSubview:table];
    [table release];

    //Add Gesture Recognizer
    swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)];
    [table addGestureRecognizer:swipeLeftRecognizer];
    [swipeLeftRecognizer release];

And somewhere in your controller;

-(void)handleSwipeFrom {

    if (swipeLeftRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {

        // Your code here to go back to the main view

    }

}

This will react only for a right swipe and will let your table behave the normal way. Hope this helps! :)

一身仙ぐ女味 2024-12-10 02:56:22

经过长时间的谷歌搜索,我找到了解决方案。我正在采用宽度为 3 个屏幕的滚动视图,并在其第一个屏幕框架上添加日历 xib 视图,在其第二个屏幕框架上添加主页 xib 视图,然后在其第三个屏幕框架上添加列表 xib 视图,以此我创建一个 UINavigationController *navigationHome;
id 父控制器;
在主屏幕上用于从滚动视图管理主屏幕导航,并对其余控制器使用相同的技术,这对我来说效果很好。

After a long googling i found a solution. I am taking a scrollview with width of 3 screens and add calendar xib view on it's first screen frame, add home xib view on it's second screen frame and then add list xib view on it's third screen frame, with this i create a UINavigationController *navigationHome;
id parentController;
on home screen for managing home screen navigation from scrollview and make same technique for rest of the controllers this will work me fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文