土特产直营建设网站的调研,网站怎样关键词排名优化,国网商城,建设报考网站查询成绩iPhone Development Blog系列: 如何制作服务条例窗口 最近一直关注iPhone Development Blog上面的文章#xff0c;学习的同时尝试通过翻译和整理同大家一起分享#xff01; 假设你想让你的每个客户在使用iPhone应用前接受你的服务条例#xff08;Terms of Services#xff… iPhone Development Blog系列: 如何制作服务条例窗口 最近一直关注iPhone Development Blog上面的文章学习的同时尝试通过翻译和整理同大家一起分享 假设你想让你的每个客户在使用iPhone应用前接受你的服务条例Terms of Services或其他一些法律声明。 在启动时显示 通过Xcode生成的标准AppDelegate代码会创建并显示你的第一个应用界面。这是一个你可以通过UIView的hidden属性在不用打断应用接下来的流程情况下显示新界面的地方。 // Create window self.window [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [window setBackgroundColor:[UIColor whiteColor]]; // Set up main view navigation controller MainMenuViewController *navController [[MainMenuViewController alloc] init]; // Create a navigation controller using the new controller navigationController [[UINavigationController alloc] initWithRootViewController:navController]; navigationController.navigationBarStyle UIBarStyleDefault; [navController release]; // Create Terms of Service screen tosController [[TermsOfServiceViewController alloc] init]; [window addSubview:[tosController view]]; navigationController.view.hidden YES; // Add the navigation controllers view to the window [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; 大部分的基础代码都是Xcode生成的。新增代码从第14行开始。实例化TermsOfServiceViewController 并加入到视图中。重要的是第17行它隐藏了navigationController。 关闭新窗口 现在已经显示了服务条例窗口并且主菜单已经隐藏。我们需要关闭服务条例窗口并回到正常的应用流程。 在AppDelegate类中创建一个新方法 - (void)termsOfServiceAccepted { tosController.view.hidden YES; navigationController.view.hidden NO; } 在TermsOfServiceController中需要添加一个用户点击的按钮 UIButton *acceptButton [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; acceptButton.frame CGRectMake(kLeftMargin, applicationFrame.size.height - kBottomMargin - kButtonHeight, applicationFrame.size.width - kLeftMargin - kRightMargin, kButtonHeight); [acceptButton setTitle:NSLocalizedString(ButtonAcceptTermsOfService, ) forStates:UIControlStateNormal]; [acceptButton addTarget:self action:selector(termsOfServiceAccepted:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:acceptButton]; 当点击按钮后就会调用相应的选择器并调用上述提到的AppDelegate中的方法。 - (void)termsOfServiceAccepted:(id)sender { id applicationDelegate [[UIApplication sharedApplication] delegate]; [applicationDelegate termsOfServiceAccepted]; } 只显示一次 利用上述代码服务条例窗口会在每次程序启动的时候都显示。这会很烦人。我们需要加些代码来使其只在NSUserDefaults中的布尔中为YES的时候显示。. NSUserDefaults *userDefaults [NSUserDefaults standardUserDefaults]; if (![userDefaults boolForKey:TERMS_OF_USE_ACCEPTED]) { tosController [[TermsOfServiceViewController alloc] init]; [window addSubview:[tosController view]]; navigationController.view.hidden YES; } 在termsOfServiceAccepted方法中设置存储在NSUserDefaults内的布尔值。 - (void)termsOfServiceAccepted { tosController.view.hidden YES; navigationController.view.hidden NO; // Store acceptance in UserDefaults NSUserDefaults *userDefaults [NSUserDefaults standardUserDefaults]; [userDefaults setBool:YES forKey:TERMS_OF_USE_ACCEPTED]; } 这样只要用户点击接受按钮后服务条例窗体就不显示了。你的客户和法律顾问都会满意的。 原文出处http://iphoneincubator.com/blog/windows-views/how-to-create-a-terms-of-service-screen 转载于:https://blog.51cto.com/bj007/412477