(iphone)制作自定义活动指标的单身?

时间:2023-01-22 17:13:46

I'm trying to add my custom activity indicator to my app.

我正在尝试将自定义活动指示符添加到我的应用中。

Since there are many places I want to show the indicator,
I thought maybe it's a good idea to make it singleton to access it easily.

由于有很多地方我想要显示指标,我想也许这是一个好主意,让单身人士轻松访问它。

I guess I can slightly modify this to make the desired singleton class. Singleton Class iPhone

我想我可以稍微修改它来制作所需的单例类。 Singleton Class iPhone

One problem is that I need to add the indicator view to some view(as subview) obviously.
And wonder if there is a singleton -like view that I can access from anywhere to add the indicator view as subview.

一个问题是我需要将指标视图显然添加到某个视图(作为子视图)。并且想知道是否存在我可以从任何地方访问的单一类似视图以将指示符视图添加为子视图。

Thank you

谢谢

3 个解决方案

#1


1  

you can use singleton, but I would advise you not to use singleton for UIView elements.

你可以使用单例,但我建议你不要使用单例来表示UIView元素。

UIView elements can only have one superview, so if you use singleton.activityindicator everywhere, you will have to remove it from superview before adding it to new view, so alot of bookkeeping is required. For example, you have to remove it from prev superview when showing it else where, and when you come back to prev superview (through user clicking on some nav control or something), you have to determine if you need to now add it back to the new superview, etc.

UIView元素只能有一个superview,因此如果你在任何地方使用singleton.activityindicator,你必须在将它添加到新视图之前将其从superview中删除,因此需要大量的簿记。例如,你必须在显示其他位置时将其从prev superview中删除,当你回到prev superview时(通过用户点击一些导航控件或其他东西),你必须确定是否需要现在将它添加回新的超级视图等

I do use singleton for one UIView in my design, that is Ad banner view. I wanted to keep one ad across the app, to have same ad in different nav controllers. However it was big pain in the butt.

我在我的设计中使用单例作为一个UIView,即广告横幅视图。我想在整个应用中保留一个广告,以便在不同的导航控件中使用相同的广告。然而,这是一个巨大的痛苦的屁股。

Just create one, add to the view, and remove when done.. simpler in my opinion :)

只需创建一个,添加到视图,并在完成后删除..在我看来更简单:)

#2


0  

You can try to add a UIView to the custom class and then add the activityIndicator to it.

您可以尝试将UIView添加到自定义类,然后将activityIndi​​cator添加到它。

#3


-1  

Take a UIView Class

参加UIView课程

inside initWithFrame methode:

在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;

Take a methode:

采取一种方法:

// call this methode from the class where u want to animate custom indicator
(void)startAnimating
{
    [customActivityIndicatorstartAnimating];
}

Take a methode:

采取一种方法:

// call this methode from the class where u want to stope animate custom 
(void)stopAnimating 
{
    [customActivityIndicatorstaopAnimating];
} 

#1


1  

you can use singleton, but I would advise you not to use singleton for UIView elements.

你可以使用单例,但我建议你不要使用单例来表示UIView元素。

UIView elements can only have one superview, so if you use singleton.activityindicator everywhere, you will have to remove it from superview before adding it to new view, so alot of bookkeeping is required. For example, you have to remove it from prev superview when showing it else where, and when you come back to prev superview (through user clicking on some nav control or something), you have to determine if you need to now add it back to the new superview, etc.

UIView元素只能有一个superview,因此如果你在任何地方使用singleton.activityindicator,你必须在将它添加到新视图之前将其从superview中删除,因此需要大量的簿记。例如,你必须在显示其他位置时将其从prev superview中删除,当你回到prev superview时(通过用户点击一些导航控件或其他东西),你必须确定是否需要现在将它添加回新的超级视图等

I do use singleton for one UIView in my design, that is Ad banner view. I wanted to keep one ad across the app, to have same ad in different nav controllers. However it was big pain in the butt.

我在我的设计中使用单例作为一个UIView,即广告横幅视图。我想在整个应用中保留一个广告,以便在不同的导航控件中使用相同的广告。然而,这是一个巨大的痛苦的屁股。

Just create one, add to the view, and remove when done.. simpler in my opinion :)

只需创建一个,添加到视图,并在完成后删除..在我看来更简单:)

#2


0  

You can try to add a UIView to the custom class and then add the activityIndicator to it.

您可以尝试将UIView添加到自定义类,然后将activityIndi​​cator添加到它。

#3


-1  

Take a UIView Class

参加UIView课程

inside initWithFrame methode:

在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;

Take a methode:

采取一种方法:

// call this methode from the class where u want to animate custom indicator
(void)startAnimating
{
    [customActivityIndicatorstartAnimating];
}

Take a methode:

采取一种方法:

// call this methode from the class where u want to stope animate custom 
(void)stopAnimating 
{
    [customActivityIndicatorstaopAnimating];
}