Iphone 启动画面

标签 iphone objective-c animation splash-screen

我确实在尽力而为,但我无法真正找出我的代码中出了什么问题。我进行了很多搜索,但我想我只是无法理解一些 Objective C 基础知识;)

我的第一个问题与下面的代码有关:

[window addSubview:tabBarController.view];

UIImage *image = [UIImage imageNamed:@"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image];

这样做有什么不同吗:

[window addSubview:defaultImage];

或者这个:

[tabBarController.view addSubview:defaultImage];

我的第二个问题是关于创建启动画面的。我试着自己做,但我无法找出什么不起作用(我们在 appDelegate 中):

[window addSubview:tabBarController.view];

UIImage *image = [UIImage imageNamed:@"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image]; 

[window addSubview:defaultImage];
[window makeKeyAndVisible]; //makes the window visible right ?

UIImage *image2 = [UIImage imageNamed:@"lol2.png"];
UIImageView *pubImage = [[UIImageView alloc] initWithImage:image2];

[UIView setAnimationDelegate:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; //not sure about the forView:window ...

[defaultImage removeFromSuperview];
[window addSubview:pubImage];

[UIView commitAnimations];

嗯,我想既然我调用了“makekeyandvisible”窗口应该是可见的并且应该向用户显示动画......

好吧,我错过了一个步骤,因为它不起作用 :D。

欢迎帮助,

高捷。

最佳答案

如果您将名为“Default.png”的图像添加到您的项目中,它将充当初始屏幕。

强制您的用户看屏幕的时间超过必要时间通常被认为是不好的。

如果您确实想使用 addSubview 添加一个:应该可以正常工作,如果您想要动画,您可能需要查看 CATransitions 而不是 UIView 动画。

将启动画面添加到窗口或主视图 Controller 应该对用户显示相同。

编辑: 试试这个片段——你需要 #include <QuartzCore/QuartzCore.h>并添加 QuartzCore 框架

// Using a CATransition
    CATransition* transition = [CATransition animation];
    transition.delegate = self; // if you set this, implement the method below
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromRight;
    [self.view.layer addAnimation: transition forKey: nil];
    [self.view addSubview: theNewView];

如果您需要在转换完成后执行某些操作,请添加此内容:

#pragma mark -
#pragma mark CAAnimation Delegate Methods
- (void)animationDidStop: (CAAnimation*)theAnimation finished: (BOOL)flag
{
    // Whatever you need to do when the animation is done.
}

关于Iphone 启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2254351/

相关文章:

iphone - 有带控件的iOS音乐播放器吗?

iphone - 在标签栏 Controller 之前显示登录屏幕

iphone - 如何在应用程序未运行时检测iphone是否同步

objective-c - 使用 SDWebImage 时构建失败

Android布局动画问题

ios - 是否有可能知道我的应用程序是否是第一次在 xcode 中运行?

ios - 为什么不能使用对象初始化此NSArray?

html - 在 IOS 8 中解析 HTML 并获取特定标签

javascript - CSS 动画创作

python - 更新 Popup.Animated 以播放 gif 直到外部任务完成 (PYSimpleGUI)