简体   繁体   English

如何在iPhone SDK中轻扫/弹出控制器?

[英]How to push/pop controller by swipe in iPhone SDK?

Currently i am developing an iPhone application in which navigation between two controls by swipe gesture recognizer. 目前我正在开发一个iPhone应用程序,通过滑动手势识别器在两个控件之间导航。

Applicaiton structure is like this Applicaiton结构是这样的 在此输入图像描述

For this i first load calendar screen and on it's view did load, i load home screen by using PushViewController. 为此我首先加载日历屏幕,并在其视图上加载,我使用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. 在主屏幕上,如果用户向左滑动,则日历屏幕显示使用PopViewController,或者如果用户滑动他的权利,则由PushViewController显示listview屏幕。 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. 现在的问题是,在我的listview屏幕上,我使用的是UITableViewController,其中Gesture Recognizer无法正常工作,有时它无法刷卡。

How can i swipe between these screen perfectly, I want to swipe same as scrollview scrolling. 如何在这些屏幕之间完美滑动,我想要像滚动视图滚动一样滑动。

Please provide me some solution. 请给我一些解决方案。

Provided your app is on iOS 3.2 or above, you can do this with a UISwipeGestureRecognizer as follows. 如果您的应用程序在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];

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! 希望这可以帮助! :) :)

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; 我正在使用宽度为3个屏幕的滚动视图,并在它的第一个屏幕框架上添加日历xib视图,在它的第二个屏幕框架上添加home xib视图,然后在它的第三个屏幕框架上添加列表xib视图,我创建了一个UINavigationController *navigationHome; id parentController; 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. 在主屏幕上用于管理来自scrollview的主屏幕导航,并为其余的控制器制作相同的技术,这将很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM