(iPhone)制作自定义活动指标的单例?

我正在尝试将自定义活动指示符添加到我的应用中。 由于有很多地方我想要显示指标, 我想也许让单身人士轻松访问它是一个好主意。 我想我可以稍微修改它来制作所需的单例类。 Singleton Class iPhone 一个问题是我需要将指标视图显然添加到某个视图(作为子视图)。 并且想知道是否存在我可以从任何地方访问的单一类似视图以将指示符视图添加为子视图。 谢谢     
已邀请:
你可以使用单例,但我建议你不要使用单例来表示UIView元素。 UIView元素只能有一个superview,所以如果你在任何地方使用singleton.activityindicator,你必须在将它添加到新视图之前将其从superview中删除,因此需要大量的簿记。例如,你必须将它从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];
} 
    

要回复问题请先登录注册