我已经创建了一个基于视图的应用程序,它正在加载默认视图......
我的默认视图是启动画面..
我想要实现的是一旦默认视图(启动视图)完成加载,几秒钟后它会加载另一个视图,即隐私策略或应用程序屏幕。
AppDelegate.m中的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
没有像往常一样改变......
上面的代码从splashscreen.xib文件加载视图
以下代码位于splashscreen.m
- (IBAction)loadPrivacyScreen {
NSLog(@"Switching To Another View");
PrivacyPolicyView *modal = [[PrivacyPolicyView alloc]initWithNibName:nil bundle:nil];
modal.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:modal animated:YES];
[modal release];
}
- (void)viewDidLoad {
[super viewDidLoad];
sleep(3);
[self loadPrivacyScreen];
// Do any additional setup after loading the view from its nib.
}
三秒后它会进入loadPrivacyScreen函数,但不会加载视图。
- (IBAction)loadPrivacyScreen;
我已经创建了一个IBAction方法,因为我想用隐私屏幕上的按钮挂钩该方法以检查该功能是否有效......
令人惊讶的是,当您单击按钮时它会起作用。但它确实按时完成。
有谁能告诉我,我做错了什么?或任何其他替代方案来实现同样的事情??
注意:我也尝试更改
- (IBAction)loadPrivacyScreen;
到
- (void)loadPrivacyScreen;
但结果仍然相同。它没有转换......
答案 0 :(得分:0)
首先,iOS提供了一种加载启动画面的简单方法。 只需在名为default.png的名称中添加一个320x480分辨率的图像,并将其添加到项目中,它将自动将此图像用作启动画面图像。
以您的方式使用计时器调用loadPrivacy屏幕。
- (void)viewDidLoad {
[super viewDidLoad];
NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:3.00 target:self selector:@selector(loadPrivacyScreen) userInfo:nil repeats:NO];
}
答案 1 :(得分:0)
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[viewController showSplash];
}
在视图控制器中,定义类似
的方法> IBOutlet UIView *modelView;
- (void)showSplash;
- (void)hideSplash;
-(void)showSplash {
UIViewController *modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
}
//hide splash screen
- (void)hideSplash {
[[self modalViewController] dismissModalViewControllerAnimated:YES];
}