iPhone-SDK:启动期间的活动指示器?

时间:2009-09-16 19:27:29

标签: iphone

我的项目中有一个Default.png文件,因此只要我的应用程序启动Default.png文件,就会在那里加载。由于我的应用程序在启动时(应用程序启动)从服务器检索数据,我想在Default.png文件加载时显示活动指示符。是否可以一次激活两个进程,我的意思是在启动期间一次显示Default.png并启用活动指示器? 但我尝试将Activity Indicator代码放在'applicationDidFinishLaunching'中,但在显示Default.png文件时它没有显示活动指示器。但我确信活动代码我所拥有的,在其他屏幕上工作正常。问题仅在应用启动期间。

有人可以分享您的想法吗?

感谢。

来福/

4 个答案:

答案 0 :(得分:4)

您无法在Default.png图像中执行任何动画。您应该使用视图/控制器(包含活动指示器)尽快替换它。比显示控制器后,加载您的数据和可能的其他控制器(在一个线程中)。

答案 1 :(得分:0)

我在我的应用程序中执行的操作是立即使用覆盖屏幕的Default.png图像加载imageview。然后,当您在后台线程上执行服务器工作时,可以在imageview上添加进度指示器。

你应该始终避免applicationDidLaunch方法中的网络活动,因为此方法有一个超时,如果它没有返回,Apple将终止你的应用程序。这很重要,因为说用户处于边缘状态且服务器出行需要30秒 - 您的应用程序似乎已经崩溃给用户。

通过在后台线程中执行网络工作并返回applicationDidLaunch,您将阻止Apple杀死您的应用,您可以让用户在新数据进入之前使用该应用(如果您需要)和您的应用似乎会更快启动。

答案 2 :(得分:0)

你应该总是避免在applicationDidLaunch方法中使用net活动,因为此方法有一个超时,如果它没有返回,Apple将终止你的应用程序。这很重要,因为说用户处于边缘状态且服务器出行需要30秒 - 您的应用程序似乎已经崩溃给用户。

所以你认为我不应该把XMLPraser放在applicationDidLaunch上?

NSURL *url = [[NSURL alloc] initWithString:@"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];

//Set delegate
[xmlParser setDelegate:parser];

//Start parsing the XML file.
BOOL success = [xmlParser parse];

if(success)
    NSLog(@"No Errors");
else
    NSLog(@"Error Error Error!!!");

答案 3 :(得分:0)

这就是它的工作原理:
(在Xcode版本4.2.1上制作)

所以......

在AppDelegate.h中添加:

@property (nonatomic, strong) UIImageView *splashView;

在AppDelegate.m中添加:

在cours页面的顶部@synthesize splashView;
然后:

- (void) splashFade
{
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"Default.png"];
    [_window addSubview:splashView];
    [_window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelay:2.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    [UIView commitAnimations];

    //Create and add the Activity Indicator to splashView
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityIndicator.alpha = 1.0;
    activityIndicator.center = CGPointMake(160, 360);
    activityIndicator.hidesWhenStopped = NO;
    [splashView addSubview:activityIndicator];
    [activityIndicator startAnimating];
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    [splashView removeFromSuperview];
}

[UIView setAnimationDelay:2.5] 负责根据您选择的延迟时间将splashView放在前面多长时间。

您可以通过更改x / y中的nubmers来改变指标的位置:
activityIndi​​cator.center = CGPointMake(160,360);

最后,根据方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

只需添加:

[self performSelector:@selector(splashFade) withObject:nil];

然后你去:) 希望它有所帮助。

有一个很好的编程......