Ios 重定向到FirstViewController
我正在用不同的Viewcontroller为不同的屏幕设置应用程序。我有按钮点击、播放视频和加载html页面等。如果我在second view controller中打开应用程序和我的应用程序,那么我在1分钟内没有做任何事情,例如应用程序中的任何点击事件或任何触摸事件,我能自动重定向到first view controller吗?可能吗Ios 重定向到FirstViewController,ios,objective-c,uiviewcontroller,viewcontroller,Ios,Objective C,Uiviewcontroller,Viewcontroller,我正在用不同的Viewcontroller为不同的屏幕设置应用程序。我有按钮点击、播放视频和加载html页面等。如果我在second view controller中打开应用程序和我的应用程序,那么我在1分钟内没有做任何事情,例如应用程序中的任何点击事件或任何触摸事件,我能自动重定向到first view controller吗?可能吗 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup a
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
video=[[VideoViewController alloc]init];
[self.navigationController.navigationBar setHidden:YES];
bgImg=[[UIImageView alloc]init];
[bgImg setFrame:CGRectMake(0,0,1024,768)];
[bgImg setImage:[UIImage imageNamed:@"home_bg.png"]];
[bgImg setUserInteractionEnabled:YES];
[self.view addSubview:bgImg];
video_play=[UIButton buttonWithType:UIButtonTypeCustom];
// [info_btn setFrame:CGRectMake(240,10 ,13, 24)];
[video_play setFrame:CGRectMake(118,300,362,202)];
[video_play setImage:[UIImage imageNamed:@"video.png"] forState:UIControlStateNormal];
[video_play addTarget:self action:@selector(watchvideo:) forControlEvents:UIControlEventTouchUpInside];
//[rhymesbgImg addSubview:info_btn];
[bgImg addSubview:video_play];
watch_video=[UIButton buttonWithType:UIButtonTypeCustom];
// [info_btn setFrame:CGRectMake(240,10 ,13, 24)];
[watch_video setFrame:CGRectMake(180,600,232,60)];
[watch_video setImage:[UIImage imageNamed:@"watch-video.png"] forState:UIControlStateNormal];
[watch_video addTarget:self action:@selector(watchvideo:) forControlEvents:UIControlEventTouchUpInside];
//[rhymesbgImg addSubview:info_btn];
[bgImg addSubview:watch_video];
[self performSelector:@selector(goToRootViewController) withObject:nil afterDelay:20.0];
}
单击事件按钮:
-(void)watchvideo:(id)sender{
// [self performSelector:@selector(goToRootViewController) withObject:nil afterDelay:20.0];
[bgImg setHidden:YES];
[watch_video setHidden:YES];
[estimate_yoursaving setHidden:YES];
NSString *pathToBundle = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:pathToBundle];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
//CGRect fullScreenRect=[[UIScreen mainScreen]applicationFrame];
web=[[UIWebView alloc]initWithFrame:CGRectMake(172, 210, 680, 380)];
[web loadHTMLString:htmlString baseURL:baseURL];
}
-(void)estimatesavings:(id)sender{
// [self performSelector:@selector(goToRootViewController) withObject:nil afterDelay:20.0];
[web loadHTMLString:nil baseURL:nil];
NSString *pathToBundle = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:pathToBundle];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
//CGRect fullScreenRect=[[UIScreen mainScreen]applicationFrame];
web_estimate=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
[web_estimate loadHTMLString:htmlString baseURL:baseURL];
web_estimate.delegate=self;
[self.view addSubview:web_estimate];
}
触摸事件:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
isTouched = YES;
NSLog(@"Touches happening");
}
- (void)goToRootViewController
{
if (isTouched == NO) {
// [self.navigationController popToRootViewControllerAnimated:YES];
NSLog(@"Touches Not Happening");
[bgImg setHidden:NO];
[watch_video setHidden:NO];
[estimate_yoursaving setHidden:NO];
[web setHidden:YES];
[web_estimate setHidden:YES];
}
}
是的,当然。您可以弹出到根视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];
编辑
您可以通过此委托方法跟踪触摸事件
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
isTouched = YES;
}
在类中添加一个方法
- (void)goToRootViewController
{
if (isTouched == NO) {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
从viewDidLoad调用此方法,方法为:
您的视图没有加载方法添加此代码
[self performSelector:@selector(pushOrPOP) withObject:nil afterDelay:1.0];
及
如何导航ViewController?
[self performSelector:@selector(pushOrPOP) withObject:nil afterDelay:1.0];
-(void)pushOrPOP
{
[self.navigationController pushViewController:[[secViewController alloc]init] animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES];
}