一段时间后通过动画将视图从一个 xib 更改为另一个 xib

发布于 2024-11-27 09:01:29 字数 1469 浏览 2 评论 0原文

我制作了一个基于视图的应用程序,它正在加载默认视图...

我的默认视图是启动屏幕..

我想要实现的是一旦默认视图(启动视图)完成加载,几秒钟后它会加载另一个视图,即隐私政策或应用程序屏幕。

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;

但结果仍然相同。不是切换的....

I have made a view based application which is loading a default view ...

My default view is a splash screen ..

What I want to achieve is once default view (splash view) finished loading, after few seconds it loads another view which is either a privacy policy or application screen.

Code in 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;
}

No Change as usual ...

Above code load a view from splashscreen.xib file

Following code is in 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.
}

After three second it does get in to the loadPrivacyScreen funciton but doesn't load the view.

- (IBAction)loadPrivacyScreen;

I have created a method as IBAction because I want to hook that method with a button on privacy screen to check that function works ...

And surprisingly it works when you click the button. But it doest work on time.

Can anyone suggest me what am I doing wrong ?? or any other alternative to achieve same thing??

Note: I have also try changing

- (IBAction)loadPrivacyScreen;

to

- (void)loadPrivacyScreen;

But still same result. It is not switching ....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日久见人心 2024-12-04 09:01:29

首先,iOS 提供了一种简单的方法来加载闪屏。
只需添加一个名为 default.png 的分辨率为 320x480 的图像,并将其添加到您的项目中,它就会自动使用该图像作为启动屏幕图像。

以您的方式调用带有计时器的 loadPrivacy 屏幕。

- (void)viewDidLoad {
   [super viewDidLoad];
   NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:3.00 target:self selector:@selector(loadPrivacyScreen) userInfo:nil repeats:NO];

}

First of all iOS provides a simple way to load a splash screen.
Just add a Image with 320x480 resolution in the name called default.png and add that to your project it will automatically use this image as splash screen image.

In your way call the loadPrivacy screen with a timer.

- (void)viewDidLoad {
   [super viewDidLoad];
   NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:3.00 target:self selector:@selector(loadPrivacyScreen) userInfo:nil repeats:NO];

}
铜锣湾横着走 2024-12-04 09:01:29
- (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];
}
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window.rootViewController = self.viewController;    
    [self.window makeKeyAndVisible];
    [viewController showSplash];
}

And in the view controller, define a method like

> 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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文