以编程方式将活动指示器添加到视图[重复]

2024-01-04

可能的重复:
在应用程序启动期间显示活动指示器 https://stackoverflow.com/questions/6849072/show-activity-indicator-during-application-launch

All,

在我的应用程序委托中,我创建了一个使用 Default.png 的动画启动视图。一切正常,但我无法弄清楚如何让我的 ActivityIndi​​cator 显示在启动视图顶部。它就隐藏在启动视图中。这是我所拥有的并致谢:

- (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 上制作)

So...

在 AppDelegate.h 中添加以下内容:

@property (nonatomic, strong) UIImageView *splashView;

在 AppDelegate.m 中添加以下内容:

课程页面顶部@synthesizesplashView;
进而:

- (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];
}

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

您可以通过更改 x/y 的数字来更改指示器的位置:
ActivityIndi​​cator.center = CGPointMake(160, 360);

最后,根据方法:

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

只需添加以下内容:

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

就这样吧:)
希望有帮助。

祝你编程愉快......

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

以编程方式将活动指示器添加到视图[重复] 的相关文章

随机推荐

  • 如何以编程方式向 contentPlaceHolder 添加内容?

    我有一个母版页 我的所有页面都继承它 对于格式设置 我想将一页与另一页不同的内容放置在 ContentPlaceHolder 中 现在 我怎样才能将所有内容插入其中 由于我计划用数据库中的内容填充 ContentPlaceHolder 我想
  • Spring 中的拦截器与方面?

    我正在尝试在 Spring 中使用拦截器 我想在某些方法上实现拦截器 以在调用这些方法时处理特定逻辑 我还想不使用 Web 框架 因为我倾向于使用 Spring 作为后端 而不使用任何标头 经过搜索 我认为 spring 方法称为方面 您能
  • git 仅从一个分支删除文件

    当我从一个分支删除文件时 它会从所有分支中删除 我能做些什么 使用 git 删除文件并保留该项目状态时 git commit 它只会在该提交及其子项中被删除 说 在该分支中 当将该分支合并到另一个分支时 该文件很可能会被删除 除非在另一个分
  • 如何导出共享案例类的属性

    我正在尝试在服务器和客户端之间共享案例类 我在两端都使用了 upickle 对象及其数据在两端都可以很好地使用 共享类 case class Foo var id Long var title Description 但是我需要在客户端导出
  • 在 iOS 设备上尝试时 Flutter 签名无效

    TL DR 编辑 2020 05 06 我的应用程序从 iOS 13 4 开始正确安装 但一段时间后应用程序在启动时崩溃 我必须重新安装它 我不知道为什么 也许是在 iOS 更新之后 另请参阅下面的答案 https stackoverflo
  • 如何从 python 3.5 脚本创建独立的可执行文件?

    大多数可用程序仅支持 python 版本 3 4 您可以使用py安装程序 http www pyinstaller org支持Python 3 5 要使用 pip 安装它 请在终端中执行 pip install pyinstaller 要制
  • Javascript 匹配在 IE 中不起作用

    我有以下代码 function rgb2hex rgb rgb rgb match rgb d s d s d return hex rgb 1 hex rgb 2 hex rgb 3 似乎在 FF 和 Chrome 中工作正常 IE 给出
  • MavengeneratePackage用于从模式定义生成类的wsdl

    我正在使用 Java14 和 Spring Boot 我需要基于 wsdl 生成一些 Java 类 然而 它正在生成 它将所有生成的类放在平面结构中 而不是放在 wsdl 中指定的包中 如果有人可以提供一些建议 我将不胜感激 更多细节 PO
  • 更改单选按钮图像,帮助

    大家好 我不是一个很好的程序员 但仍然需要做一些编码 现在我在使用 jQuery 更改单选按钮图像时遇到问题 我已经在网上找到了这段代码 但它仍然不起作用 它更改了单选按钮图像 但是当我尝试选择时 它仅更改第一个单选框的图片 每次 这是我的
  • C# List<> 将列表添加到字典

    Dictionary
  • 使用列表元素的名称向列表中的每个数据框添加一列

    我有一个包含多个数据框的列表 每个列表元素都有一个唯一的名称 结构类似于这个虚拟数据 a lt data frame z rnorm 20 y rnorm 20 b lt data frame z rnorm 30 y rnorm 30 c
  • 我如何创建带有下面文本视图的按钮网格

    Hi 我想创建一个像我 尝试 上面绘制的屏幕 A b c d e f g 和 h 是buttons p 是一个EditText 现在我想要完成的是 当部署在更大或更小的屏幕上或旋转时 会发生以下情况 元素 p 保持相同的高度 但水平尺寸 获
  • C# - 抛出异常时无限循环?

    我有以下代码 protected void ExecuteInTransaction Action action using SQLiteTransaction transaction connection BeginTransaction
  • 当另一个字段发生实际变化时,sql server触发器更新时间字段

    我需要一个触发器 如果 表行的一个或多个字段被更新 该触发器就会更新该行字段 假设您有一个雇员表 如下所示 EmployeeId Name Address ModificationDate 1 Spears 27 Sober Road 2
  • 带缓动的动画画布弧线

    我正在画布上画一个非传统的环形时钟 时间由秒环 秒针 分钟环和小时环表示 我正在使用 webkit mozRequestAnimationFrame 在适当的时间进行绘制 我想修改第二个环以快速动画到下一秒 125ms 250ms 并使用二
  • 如何在Python3中使用自签名证书

    我已在 Windows Server 2012 R2 WSUS 服务器 10 66 194 98 Dec15 cer 中生成了自签名证书 并在所有 WSUS 管理 网站中启用了 SSL 现在我想在 python 代码中使用它来与服务器联系
  • Android USB API:在充电和数据发送之间切换

    我开始使用 Android USB API 将数据从 Arduino 发送到 Android 设备 是否可以以编程方式在发送 接收数据之间切换并只为 Android 手机充电 我知道你不能同时做这两件事 而且 因为你必须打开一个FileIn
  • NSUserDefaults 有哪些限制?

    在 iPhone 中永久存储数据通常是使用 Core Data 或 sqlite3 完成的 大多数人更喜欢使用 NSUserDefaults 作为应用程序首选项的存储 而不是将其用作普通数据库 例如 sqlite 我发现 NSUserDef
  • Charts Pod 未降级

    我正在使用 Xcode 8 3 和 swift 3 为了使用图表库 我需要使用 Charts 3 0 2 但 Cocoapods 始终安装最新的库 我尝试执行以下命令 pod install pod update but none are
  • 以编程方式将活动指示器添加到视图[重复]

    这个问题在这里已经有答案了 可能的重复 在应用程序启动期间显示活动指示器 https stackoverflow com questions 6849072 show activity indicator during applicatio