0

我一直想在我的 iPhone 应用程序中制作一个循环预加载器,但一直在努力从哪里开始。我今天在使用 Sequel Pro,发现他们正是我想要的,而且它是开源的,所以我下载了源代码,但找不到任何东西。

我只是在寻找如何制作以下内容的开始:

替代文字 http://www.grabup.com/uploads/c7b2d101cd9caf0d927c2fa8a7850ba2.png

或者

替代文字 http://www.grabup.com/uploads/fc8520a4425331a3a6a0cbf6508b510f.png

我找到了一些 Flash 教程,但很难将其转化为 Objective-C 中的可用代码。

提前致谢。

4

4 回答 4

3

为此目的创建 UIView 子类并不难。在子类中,您可能希望在drawRect例程中大致执行以下操作:

CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat      center_x = self.frame.size.width / 2;
CGFloat      center_y = self.frame.size.height / 2;
double       progress = 0.42; // A floating-point number from 0..1 inclusively

// draw the frame
CGContextAddArc(context,
                center_x,
                center_y,
                std::min(self.frame.size.width, self.frame.size.height),
                0,
                M_PI * 2,
                1 /*clockwise*/);
CGContextStrokePath(context);

// draw the progress indicator
CGContextAddArc(context,
                center_x,
                center_y,
                std::min(self.frame.size.width, self.frame.size.height),
                0,
                M_PI * 2 * progress,
                1 /*clockwise*/);
CGContextFillPath(context);
于 2009-08-31T21:30:23.100 回答
1

您应该使用 AnimatedGif 库,并从 preloaders.net 或其他网站下载动画 GIF。

只需以编程方式进行(没有 IB)。这很简单。这是代码:

AnimatedGif *animatedGif = [[[AnimatedGif alloc] init] autorelease];    
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"circle-loader" ofType:@"gif"]]; 
[animatedGif decodeGIF: data];
self.loadingImage = [animatedGif getAnimation]; //self.loadingImage is a UIImageView
[self.view addSubview:loadingImage];

然后,稍后当您要删除 GIF 时:

[loadingImage removeFromSuperview];
[loadingImage release];
于 2009-09-02T20:27:39.510 回答
1

AnimatedGif(上面提到的)库工作得非常好。不得不在这里找到它:http: //blog.stijnspijker.nl/2009/07/animated-and-transparent-gifs-for-iphone-made-easy/

于 2010-08-27T07:00:52.900 回答
0

您的意思是进度指示器,例如 Interface Builder 中包含的进度指示器,但是是循环的?我假设您已经看过教程的 Flex 框架中有一个默认的框架。

我想你必须自己做这个。你可以做的是有一个视图来监听来自对象的进度通知。当它收到这些信息时,您将计算要显示的图像并调用 viewNeedsDisplay 方法。

我快速浏览了 Sequel Pro 的源代码,我认为您正在寻找的是 NSProgressIndicator。但 Sequel Pro 是一款桌面应用程序,比 iPhone 具有更大的灵活性。Cocoa Touch 等价物是 UIActivityIndi​​catorView,它总是不确定的(即,您不能指定完成百分比)。

编辑:是的,请参阅上面的 fbrereton 代码以了解绘图例程。

以下是您如何收听通知以获取该进度浮点值:

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(receivedProgress:)
                                                 name:@"MyProgressIndication" 
                                               object:nil];

您将从正在执行以下工作的对象中发布它们:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"MyProgressIndication"
                                                        object:[NSNumber numberFromFloat:progress]];

通知名称的常量是最好的。

于 2009-08-31T21:30:49.950 回答