这是我到目前为止所做的:
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
-(void)animate
{
[UIView animateWithDuration:1 animations:^{
splashImage.frame = CGRectMake(0,480,320,480);
}];
[UIView commitAnimations];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splashImage = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"carolinaWolf.png"]];
splashImage.frame = CGRectMake(0, 0, 320, 480);
[self.tabBarController.view addSubview:splashImage];
[self animate];
return YES;
}
我在storyboard中的初始视图是一个TabBarController。我想要发生的事情是:在我将新内容加载到应用程序中之后,我想要在屏幕上显示动画。这在我开始使用故事板之前有效,为什么它现在不起作用?
我的AppDelegate.h看起来像这样:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
UIImageView *splashImage;
答案 0 :(得分:1)
您可以直接将splashImage
添加到self.window.rootViewController
,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *splashImage = [UIImage autoAdjustImageNamed:@"Default.png"];
UIImageView *splashImageView = [[UIImageView alloc] initWithImage:splashImage];
[self.window.rootViewController.view addSubview:splashImageView];
[self.window.rootViewController.view bringSubviewToFront:splashImageView];
[UIView animateWithDuration:1.5f
delay:2.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
splashImageView.alpha = .0f;
CGFloat x = -60.0f;
CGFloat y = -120.0f;
splashImageView.frame = CGRectMake(x,
y,
splashImageView.frame.size.width-2*x,
splashImageView.frame.size.height-2*y);
} completion:^(BOOL finished){
if (finished) {
[splashImageView removeFromSuperview];
}
}];
return YES;
}
答案 1 :(得分:0)
这就是我淡出闪屏的方式:
@interface FadeDefault : UIViewController
@end
@implementation FadeDefault
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *fader = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default@2x.png"]];
[fader setFrame:CGRectMake(0,0,320,480)];
/*if ( IDIOM == IPAD ) /* Optional */
{
fader = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Portrait~ipad.png"]];
[fader setFrame:CGRectMake(0,0,768,1024)];
}else
{
fader = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default@2x.png"]];
[fader setFrame:CGRectMake(0,0,320,480)];
}*/
self.view = fader;
[fader release];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(imageDidFadeOut:finished:context:)];
self.view.alpha = 0.0;
[UIView commitAnimations];
}
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
[self.view removeFromSuperview];
}
@end
请记住这是一个示例,虽然我实际使用的代码我知道有效,但您需要保留其他didFinishLaunchingWithOptions
代码。只需将fader
代码添加到现有代码中即可。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* custom fading Default.png animation */
FadeDefault * fader = [[FadeDefault alloc] init];
[window addSubview:navigationController.view];
[window addSubview:fader.view];
[fader release];
[window makeKeyAndVisible];
return YES;
}