我确实在尽力而为,但我无法真正找出我的代码中出了什么问题。我进行了很多搜索,但我想我只是无法理解一些 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/