gpt4 book ai didi

ios - 重定向到第一个 ViewController

转载 作者:行者123 更新时间:2023-11-29 02:58:39 24 4
gpt4 key购买 nike

我正在为不同的屏幕集使用不同的 Viewcontroller 进行应用。我有按钮点击、播放视频和加载 html 页面等。如果我在第二个 View Controller 中打开应用程序和我的应用程序,那么我在 1 分钟内没有做任何事情,例如应用程序中的任何点击事件或任何触摸事件,我可以自动重定向到第一个 View Controller ?可能吗?

- (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];


}

}

最佳答案

是的,当然。您可以弹出到 Root View Controller

[self.navigationController popToRootViewControllerAnimated:YES];

编辑

您可以通过此委托(delegate)方法跟踪触摸事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
isTouched = YES;
}

在类中添加方法

- (void)goToRootViewController
{
if (isTouched == NO) {
[self.navigationController popToRootViewControllerAnimated:YES];
}

}

viewDidLoad 调用此方法:

[self performSelector:@selector(goToRootViewController) withObject:nil afterDelay:60.0];

关于ios - 重定向到第一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23557098/

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