XCode自定义活动指示器-加载UIWebView之后隐藏(webViewDidFinishLoad) [英] XCode Custom Activity Indicator - Hide after UIWebView Loads (webViewDidFinishLoad)

查看:127
本文介绍了XCode自定义活动指示器-加载UIWebView之后隐藏(webViewDidFinishLoad)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处找到的代码 http://blog.blackwhale.at/?p= 336 ,以在当前版本的xCode中创建自定义 activityIndi​​cator 。此代码使用数组中的一系列 .png 图像,然后按设置的时间间隔显示它们,以创建动画加载图像,然后将其放置在屏幕上(并假设

I'm using the code found here http://blog.blackwhale.at/?p=336 to create a custom activityIndicator in the current version of xCode. This code uses a series of .png images in an array and then displays them at the set interval to create an animated loading image that you can then place on the screen (and assuming you can somehow remove it) whenever you want.

在我的主要ViewController.m文件中,我的 viewDidLoad 部分:

In my main ViewController.m file I have the following code in my viewDidLoad section :

/* --- START CUSTOM ACTIVITY INDICATOR */
    //Create the first status image and the indicator view
    UIImage *statusImage = [UIImage imageNamed:@"activity1.png"];
    UIImageView *activityImageView = [[UIImageView alloc] 
                                      initWithImage:statusImage];


    //Add more images which will be used for the animation
    activityImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"activity1.png"],
                                         [UIImage imageNamed:@"activity2.png"],
                                         [UIImage imageNamed:@"activity3.png"],
                                         [UIImage imageNamed:@"activity4.png"],
                                         [UIImage imageNamed:@"activity5.png"],
                                         [UIImage imageNamed:@"activity6.png"],
                                         [UIImage imageNamed:@"activity7.png"],
                                         [UIImage imageNamed:@"activity8.png"],
                                         [UIImage imageNamed:@"activity9.png"],
                                         [UIImage imageNamed:@"activity10.png"],
                                         [UIImage imageNamed:@"activity11.png"],
                                         [UIImage imageNamed:@"activity12.png"],
                                         nil];


    //Set the duration of the animation (play with it
    //until it looks nice for you)
    activityImageView.animationDuration = 0.6;


    //Position the activity image view somewhere in 
    //the middle of your current view
    activityImageView.frame = CGRectMake(
                                         self.view.frame.size.width/2
                                         -statusImage.size.width/2, 
                                         self.view.frame.size.height/1.2
                                         -statusImage.size.height/1.2, 
                                         statusImage.size.width, 
                                         statusImage.size.height);

    //Start the animation
    [activityImageView startAnimating];


    //Add your custom activity indicator to your current view
    [self.view addSubview:activityImageView];


   /*  --- END CUSTOM ACTIVITY INDICATOR */

我想清除/删除/隐藏 activityImageView 元素,因为我只希望它在应用程序首次启动时显示,直到 UIWebView 完成加载。

I would like to CLEAR/DELETE/HIDE the activityImageView element, as I only want it to show when the app first launches until the UIWebView finishes loading.

我想调用它并在 webViewDidStartLoad 时显示gif,然后在 webViewDidFinishLoad 。有人帮忙吗?

I would like to call this and have the gif appear while webViewDidStartLoad and then clear when webViewDidFinishLoad. Someone help??

推荐答案

好的,所以不能访问activityImageView的原因是因为它是在viewDidLoad函数中声明的。将其作为属性添加到ViewController类中,您应该可以执行所需的操作。确保从viewDidLoad中删除activityImageView的声明,然后在此处进行初始化。

Okay, so the reason that you cannot access activityImageView is because its declared in your viewDidLoad function. Add it as a property to your ViewController class and you should be able to do what you want. Make sure that you remove the declaration of activityImageView from viewDidLoad, and just initialize it there.

此外,要在其中显示活动指示器的Web视图在哪里?它有单独的视图控制器还是包含在主视图控制器中?听起来您的activityImageView范围是错误的,尽管不知道如何设置所有内容,这让我很难告诉您放置它的位置。

Also, where is your webview that you want to show the activity indicator? Does it have a separate view controller or is it included in your main view controller? It sounds like your scope for activityImageView is incorrect, though without knowing how you have everything set up its a little hard for me to tell you where to put it.

在这两个地方使用活动指示器,您是否打算在应用程序运行时再次使用它,还是只有在重新加载应用程序后才可见?根据答案的不同,您要么只是将其隐藏,要么将其从主视图中删除。

After you use your activity indicator in these two places, do you plan on using it again during the applications run time, or will it only ever be visible if you reload the application? Depending on the answer to that you will either want to just hide it, or remove it from you main view.

UIImageView.hidden是控制可见性的工具。

UIImageView.hidden is what controls visibility.

编辑,按要求提供代码:

EDIT, Code as requested:

ViewController.h

@interface ViewController : UIViewController
{
    UIWebView *_webView;
}

@property(nonatomic, strong) UIWebView *webView;
@property(nonatomic, strong) UIImageView *activityImageView;

ViewController.m

@implementation ViewController
@synthesize activityImageView;
@synthesize webView = _webView;

-(void)viewDidLoad {

    //all your previous stuff with the change that you just alloc activityImageView instead of declare it
    activityImageView = [[UIImageView alloc] initWithImage:statusImage];
    //The above is the initialization, below is where your old code should go
}

这篇关于XCode自定义活动指示器-加载UIWebView之后隐藏(webViewDidFinishLoad)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆