以编程方式向视图添加活动指示器 [英] Adding an Activity Indicator Programmatically to a View
问题描述
可能重复:
在应用程序启动期间显示活动指示器
全部,
在我的app委托中,我创建了一个使用我的Default.png的动画启动视图。一切正常,但我无法弄清楚如何让我的ActivityIndicator显示在初始视图之上。它只是被飞溅视图所隐藏。以下是我所拥有的并感谢:
Inside my app delegate, I created an animated splash view that uses my Default.png. That all works OK but I cannot figure out how get my ActivityIndicator to display on top of the splash view. It's there just hidden by the splash view. Here is what I have and thanks:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//... data access stuff here ...
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// ... more setup stuff here ...
/****************************************************************************
*
*
* Splash Screen for iPhone
*
****************************************************************************/
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
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:0.5];
[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, -60, 440, 600);
[UIView commitAnimations];
//Create and add the Activity Indicator to splashView
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.alpha = 1.0;
activityIndicator.center = CGPointMake(160, 240);
activityIndicator.hidesWhenStopped = NO;
[splashView addSubview:activityIndicator];
[activityIndicator startAnimating];
}
return YES;
}
推荐答案
对于所有需要此项服务的人,我知道有很多...
(Xcode版本4.2.1制造)
For all those who needed this, and i know there were many...
(Made on Xcode version 4.2.1)
所以......
在AppDelegate.h中添加:
In the AppDelegate.h add this:
@property (nonatomic, strong) UIImageView *splashView;
在AppDelegate.m中添加:
In the AppDelegate.m add this:
在cours页面的顶部@synthesize splashView;
然后:
On the top of the page of cours @synthesize splashView;
And then:
- (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将在前面显示多长时间。
The [UIView setAnimationDelay:2.5] is responsible for how long the splashView will be in front by the delay time you choose.
您可以通过更改x / y中的nubmers来更改指标的位置: br>
activityIndicator.center = CGPointMake(160,360);
You can change the position of the indicator by changing the nubmers of x/y in:
activityIndicator.center = CGPointMake(160, 360);
最后,在方法下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
只需添加:
[self performSelector:@selector(splashFade) withObject:nil];
然后你去:)
希望它有所帮助。
And there you go :)
Hope it helped.
有一个很好的编程....
Have a nice programming....
这篇关于以编程方式向视图添加活动指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!