1

我需要为 iPhone 应用程序实现动画启动屏幕。我见过已经实现了相同功能的 Skype 应用程序。

谁能知道我如何在我的应用程序中实现相同的东西

4

7 回答 7

2

您可以使用图像序列,这里是代码:

for(NSInteger i=1;i<=totalImages;i++){
        NSString *strImage = [NSString stringWithFormat:@"Activity_%d",i];
        UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strImage ofType:@"png"]];
        [imageArray addObject:image];
    }
    splashImageView.animationImages = imageArray;
    splashImageView.animationDuration = 0.8;

只需调用 UIImageView 的 startAnimation 和 endAnimation 方法。

或者

它非常简单......我用它来开始我的应用程序与 splashView. 希望它对你有帮助......在 AppDelegate.m 中:

应用程序 didFinishLaunchingWithOptions:

UIImage* image=[UIImage imageNamed:@"splash.jpg"];
splashView=[[UIImageView alloc]initWithImage:image];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:@selector(removeSplash) withObject:self afterDelay:2];
[window makeKeyAndVisible];

要删除 splashView:

-(void)removeSplash{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [splashView removeFromSuperview];
    [UIView commitAnimations];
    [window addSubview:viewController.view];
}
于 2012-10-05T11:18:31.947 回答
2

将 UIView 和 Imageview 放入其中。将你所有的图像都交给 ImageView 来制作动画。

-(void)viewDidLoad
{
 NSArray *arrImage=[NSArray arrayWithObjects:
                             [UIImage imageNamed:@"1.png"],
                             [UIImage imageNamed:@"2.png"],
                             [UIImage imageNamed:@"3.png"],
                             nil];

    imgVw.backgroundColor=[UIColor purpleColor];
    imgVw.animationImages=arrImage;
    imgVw.animationDuration=2.5;
    imgVw.animationRepeatCount=1;
    [imgVw startAnimating]; 

    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(animateNext) userInfo:nil repeats:NO];

}

这将显示您的应用程序图标。

之后,您将显示默认隐藏的控件,并从下到上为它们设置动画。

-(void)animateNext
{
    lbl.hidden = NO;
    btn.hidden = NO;
    txt1.hidden = NO;
    txt2.hidden = NO;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.9];
    lbl.frame=CGRectMake(lbl.frame.origin.x,lbl.frame.origin.y - 150,lbl.frame.size.width,lbl.frame.size.height);
    imgVw.frame = CGRectMake(imgVw.frame.origin.x, imgVw.frame.origin.y - 150, imgVw.frame.size.width, imgVw.frame.size.height);
    txt1.frame = CGRectMake(txt1.frame.origin.x, txt1.frame.origin.y - 150, txt1.frame.size.width, txt1.frame.size.height);
    txt2.frame = CGRectMake(txt2.frame.origin.x, txt2.frame.origin.y - 150, txt2.frame.size.width, txt2.frame.size.height);
    btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y - 150, btn.frame.size.width, btn.frame.size.height);
    [UIView commitAnimations];    


}

希望这有助于...

于 2012-10-06T04:51:21.997 回答
2

我们可以在其中显示.gif图像webView,它看起来很完美!

取一个名为with的新UIViewController类,然后添加一个with (320.0, 480.0) 框架,也隐藏起来。SplashViewXIBUIWebViewstatusbar

SplashView.h

#import <UIKit/UIKit.h>
@interface SplashView : UIViewController
@property(nonatomic, retain)IBOutlet UIWebView *webView;
@end

SplashView.m

- (void)viewDidLoad
{
   [super viewDidLoad];
   NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"animated" ofType: @"gif"];
   NSData *data = [NSData dataWithContentsOfFile:imagePath];
   [self.webView setUserInteractionEnabled:NO];
   [self.webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
}

这是关于SplashView课堂的。现在来到你的 appdelegate 的课堂。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
     splashView = [[SplashView alloc]initWithNibName:@"SplashView" bundle:nil];
    [self.window addSubview:splashView.view];

    [self performSelector:@selector(changeView) withObject:nil afterDelay:3.0];

    [self.window makeKeyAndVisible];
    return YES;
}

-(void)changeView
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [splashView.view removeFromSuperview];
    [self.window setRootViewController:self.viewController];
}
于 2012-10-05T11:50:19.250 回答
1

尝试这个

Appdelegate.h

   @interface AppDelegate : UIResponder <UIApplicationDelegate> 
    {
        UIImageView *splashView;
    }

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

// Make this interesting.
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"Default.png"];
    [self.window addSubview:splashView];
    [self.window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    splashView.frame = CGRectMake(-60, -85, 440, 635);
    [UIView commitAnimations];

    return YES;
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [splashView removeFromSuperview];
}
于 2012-10-05T11:18:59.333 回答
1

您需要使用视图控制器启动您的应用程序,其中包含一个 uiimageview。创建一系列 .png 图像以进行 UIImageView检查如何为 uiimageview 中的图像数组设置动画。进一步要在动画结束后将其关闭,您需要实现一个协议,该协议将通知您启动应用程序的第一个视图控制器以关闭动画

于 2012-10-05T11:21:25.747 回答
0

是的,在 AppDelegate 类中很简单,首先像下面这样破坏 imageview..

@interface AppDelegate : UIResponder 
{
    UIImageView *splashView;
}

并在 .m 文件中...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        splashView.image = [UIImage imageNamed:@"Default"];
        [self.window addSubview:splashView];

        [self performSelector:@selector(loadViewIphone) withObject:nil afterDelay:2.0];
    } 
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)loadViewIphone 
{
    [splashView removeFromSuperview];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFade];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:@"transitionViewAnimation"];
}

我希望这对你有帮助..

:)

于 2012-10-05T11:19:19.717 回答
0
- (void) welcomeScreen
{

 //Welcome Screen
 UIImageView* welcome = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)]autorelease];
 welcome.image = [UIImage imageNamed:@"img.png"];
 [window addSubview:welcome];
 [window bringSubviewToFront:welcome];

 //Animation Effects (zoom and fade)
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:2.0];
 [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
 [UIView setAnimationDelegate:welcome];
 [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];

//set transparency to 0.0
 welcome.alpha = 0.0;

//zoom effect
 welcome.frame = CGRectMake(-60, -60, 440, 600);

 [UIView commitAnimations];


}
于 2012-10-05T11:20:38.467 回答