我試圖將我的自定義活動指示器添加到我的應用程序。(iPhone)使自定義活動指標的單身?
由於有很多地方我想顯示指標,我想這可能是一個不錯的主意,讓它可以很容易地訪問它。
我想我可以稍微修改這個來做所需的單例類。 Singleton Class iPhone
一個問題是,我需要添加指標視圖顯然是作爲子視圖。
並想知道是否有類似單例的觀點,我可以從任何地方訪問以將指標視圖添加爲子視圖。
謝謝
我試圖將我的自定義活動指示器添加到我的應用程序。(iPhone)使自定義活動指標的單身?
由於有很多地方我想顯示指標,我想這可能是一個不錯的主意,讓它可以很容易地訪問它。
我想我可以稍微修改這個來做所需的單例類。 Singleton Class iPhone
一個問題是,我需要添加指標視圖顯然是作爲子視圖。
並想知道是否有類似單例的觀點,我可以從任何地方訪問以將指標視圖添加爲子視圖。
謝謝
可以使用單,但我勸你不要用單對UIView的元素。
UIView元素只能有一個超級視圖,所以如果你在任何地方使用singleton.activityindicator,你必須在超級視圖中將其添加到新視圖之前,所以需要大量的簿記。例如,你必須從prev superview中刪除它,並在顯示其他位置時,以及當你回到prev superview(通過用戶點擊一些導航控件或某物)時,你必須確定是否需要現在將它添加回新的超級景觀等。
我在設計中使用單個UIView,即廣告橫幅視圖。我希望在應用中保留一個廣告,以便在不同的導航控制器中放置相同的廣告。然而,這是一個很大的痛苦。
只需創建一個,添加到視圖,當完成在我看來:)
你可以嘗試將UIView
添加到自定義類,然後添加activityIndicator
它簡單..刪除。
乘坐UIView
類
內initWithFrame
梅索德:
//this method create custom activity indicator
UIImage *startImage = [UIImage imageNamed:@"1.png"];
customActivityIndicator = [[UIImageView alloc] //take in in .h file
initWithImage:startImage ];
//Add more images which to be used for the animation
customActivityIndicator.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
nil];
//Set animation duration
customActivityIndicator.animationDuration = 0.5;
//set frame at the middle of the imageview
customActivityIndicator.frame = self.frame;
乘坐梅索德:
// call this methode from the class where u want to animate custom indicator
(void)startAnimating
{
[customActivityIndicatorstartAnimating];
}
乘坐梅索德:
// call this methode from the class where u want to stope animate custom
(void)stopAnimating
{
[customActivityIndicatorstaopAnimating];
}
這不是一個單身人士; ) – tamasgal 2012-10-29 10:19:29
我想,加入作爲子視圖自動將其從先前的超級視圖中移除。糾正我,如果我錯了請 – eugene 2011-03-16 04:25:55
讓我知道如果是。從我的測試中,它沒有從超級視圖中自動移除。當我將單身adview添加到許多超級視圖時,沒有一個超級視圖可以顯示它(它全部變黑)。另外,活動指標來來去去的情況呢?例如,假設您開始活動,所以它顯示在當前視圖中。在活動期間,您推送一個新視圖 - 然後活動結束,然後您彈出。你將如何處理你是否應該讀取活動?爲每個viewcontrlr保留活動指示符更容易,並讓每個句柄的委託方法顯示/隱藏。 – 2011-03-16 18:53:53
thx,最好的解決方案 – SamuelChan 2016-10-14 02:25:01