我使用此處找到的代碼http://blog.blackwhale.at/?p=336在當前版本的xCode中創建自定義activityIndicator
。此代碼在數組中使用一系列.png
圖像,然後按照設定的時間間隔顯示它們,以創建一個動畫加載圖像,然後您可以隨時放置在屏幕上(並假設您可以以某種方式將其刪除)。XCode自定義活動指標 - 在UIWebView加載後隱藏(webViewDidFinishLoad)
在我的主要ViewController.m文件,我在我的viewDidLoad
部分添加以下代碼:
/* --- 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
完成加載。
我想調用這個和有GIF出現而webViewDidStartLoad
,然後清除時webViewDidFinishLoad
。有人幫忙?
您是否嘗試過只是從當前視圖中刪除activityImageView動畫完成後?或者更好的是,改變能見度?或者,也許我不明白什麼阻止你在你提到的兩個函數中調用它,也許你可以澄清你遇到的問題? – 2012-07-10 20:39:01
你能告訴我該怎麼做嗎? :)喜歡什麼代碼,並把它放在哪裏?我趕上很快。這個問題(我認爲我有,但老實說,我不知道)是'activityImageView'不能在'viewDidLoad'部分之外訪問...? – adamdehaven 2012-07-10 20:41:43
好的,我知道你需要做什麼,我會在答案部分發布。 – 2012-07-10 20:43:00