iPhone应用程序-Flow Cover(封面流)显示图像

发布于 2024-11-30 12:49:25 字数 269 浏览 0 评论 0原文

在 iPhone 应用程序中,我集成了 Flow cover。我正在将图像从网络服务器加载到流封面中。

直到下载图像时,我正在传递图像计数 = 0 和 uiimage= null

这里我没有通过 viewdidload 或 viewwillAppear 等方法下载图像,实际上我已经创建了单独的线程用于下载和解析,因此加载该视图不需要时间。

下载完成后,如果触摸屏幕,它会显示所有图像,但我想在下载完成时显示图像。

如何以编程方式使图像在没有任何触摸效果的情况下可见?

In an iPhone app I have integrated flow cover. I am loading images into flow cover from web server.

Till the time images downloading i am passing image count= 0 and uiimage= null

Here I am not downloading images on methods like viewdidload or viewwillAppear actually I have created separate thread for downloading and parsing so it would not take time to load that view.

When downloading completes and if touches the screen it is showing all images but I want to display images on download completes.

How to make images visible without any touch effect programmatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

财迷小姐 2024-12-07 12:49:25

这可能会帮助您识别下载结束。由于 NSURLConnection 下载是异步的,因此您可以使用通知来标记下载何时完成并启动您的方法。

为 NSNotifications 添加观察者:

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

在完成下载后发送通知:

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [[NSNotificationCenter defaultCenter] 
            postNotificationName:@"some_name" object:nil];
}

这将启动该方法:

-(void)some_method { 
    // add downloaded image to set or smth
}

This might help you recognize the end of download. Since NSURLConnection downloading is async, you can use notification to mark when the download is finished and start your method.

Add observer for NSNotifications:

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

In finished download send the notification:

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [[NSNotificationCenter defaultCenter] 
            postNotificationName:@"some_name" object:nil];
}

And that will start the method:

-(void)some_method { 
    // add downloaded image to set or smth
}
皇甫轩 2024-12-07 12:49:25

使用 ASIHTTP 从 http://allseeing-i.com/ASIHTTPRequest/ 下载 Api

然后集成到项目中

在以下代码放入 .h 文件

#import <UIKit/UIKit.h>

#import "AFOpenFlowView.h"

#import "ASINetworkQueue.h"
#import "ASIHTTPRequest.h"

@interface cfDemoViewController : UIViewController <AFOpenFlowViewDataSource, AFOpenFlowViewDelegate> {
    ASINetworkQueue *queue;
    NSArray *coverImageData;
}
@property (nonatomic, retain) NSArray *arX;

- (void)imageDidLoad:(NSArray *)arguments;
-(void)requestForImage:(NSUInteger)index;

@end

和以下代码放入 .m 文件

#import "UIImageExtras.h"

#import "cfDemoViewController.h"

#import "UIImageExtras.h"


@implementation cfDemoViewController

@synthesize arX = _arX;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *ar=[NSArray arrayWithObjects:@"http://google.com/report_image/2/17",
                 @"http://google.com/report_image/2/16",
                 @"http://google.com/report_image/2/15",
                 @"http://google.com/report_image/2/14",
                 @"http://google.com/report_image/2/13",
                 @"http://google.com/report_image/2/12",
                 @"http://google.com/report_image/2/11",
                 @"http://google.com/report_image/2/10",
                 @"http://google.com/report_image/2/9",
                 @"http://google.com/report_image/2/8",nil];

    self.arX=ar;

    queue=[[ASINetworkQueue alloc] init];

    for (int i=0; i < [ar count]; i++) {
        [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:@"default.png"] forIndex:i];
    }

    [self requestForImage:0];

    [(AFOpenFlowView *)self.view setNumberOfImages:10]; 
}

-(void)requestForImage:(NSUInteger)index{
    if(index>=[self.arX count]) return;
    ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[self.arX objectAtIndex:index]]];
    [req setDidFinishSelector:@selector(requestDone:)];
    [req setDidFailSelector:@selector(requestWentWrong:)];
    [req setUsername:[NSString stringWithFormat:@"%i",index]];
    [req setDelegate:self];
    [queue addOperation:req];   
    [queue go];
}

- (void)requestDone:(ASIHTTPRequest *)request
{   
    NSUInteger index=[[request username] intValue]; 
    UIImage *img=[UIImage imageWithData:[request responseData]];
    img=[img cropCenterAndScaleImageToSize:CGSizeMake(225, 225)];
    [(AFOpenFlowView*)self.view setImage:img forIndex:index];

    [self requestForImage:index+1];
     // here all requests are downloaded and you want display any msg to user that code goes here.

}

- (void)requestWentWrong:(ASIHTTPRequest *)request
{
//  NSError *error = [request error];
    NSUInteger index=[[request username] intValue];
    [self requestForImage:index+1];
}


- (void)imageDidLoad:(NSArray *)arguments {
    UIImage *loadedImage = (UIImage *)[arguments objectAtIndex:0];
    NSNumber *imageIndex = (NSNumber *)[arguments objectAtIndex:1];

    // Only resize our images if they are coming from Flickr (samples are already scaled).
    // Resize the image on the main thread (UIKit is not thread safe).
    loadedImage = [loadedImage cropCenterAndScaleImageToSize:CGSizeMake(225, 225)];

    [(AFOpenFlowView *)self.view setImage:loadedImage forIndex:[imageIndex intValue]];
}

- (UIImage *)defaultImage {
    return [UIImage imageNamed:@"default.png"];
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index{
    NSLog(@"request for index - %d",index);
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index {
    NSLog(@" Hello - Cover Flow selection did change to %d", index);
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
//    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

@end

也从这里下载代码。

Use ASIHTTP Download Api From http://allseeing-i.com/ASIHTTPRequest/

Then that integrate into project

In Following Code Put into .h File

#import <UIKit/UIKit.h>

#import "AFOpenFlowView.h"

#import "ASINetworkQueue.h"
#import "ASIHTTPRequest.h"

@interface cfDemoViewController : UIViewController <AFOpenFlowViewDataSource, AFOpenFlowViewDelegate> {
    ASINetworkQueue *queue;
    NSArray *coverImageData;
}
@property (nonatomic, retain) NSArray *arX;

- (void)imageDidLoad:(NSArray *)arguments;
-(void)requestForImage:(NSUInteger)index;

@end

And Following Code Put into .m file

#import "UIImageExtras.h"

#import "cfDemoViewController.h"

#import "UIImageExtras.h"


@implementation cfDemoViewController

@synthesize arX = _arX;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *ar=[NSArray arrayWithObjects:@"http://google.com/report_image/2/17",
                 @"http://google.com/report_image/2/16",
                 @"http://google.com/report_image/2/15",
                 @"http://google.com/report_image/2/14",
                 @"http://google.com/report_image/2/13",
                 @"http://google.com/report_image/2/12",
                 @"http://google.com/report_image/2/11",
                 @"http://google.com/report_image/2/10",
                 @"http://google.com/report_image/2/9",
                 @"http://google.com/report_image/2/8",nil];

    self.arX=ar;

    queue=[[ASINetworkQueue alloc] init];

    for (int i=0; i < [ar count]; i++) {
        [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:@"default.png"] forIndex:i];
    }

    [self requestForImage:0];

    [(AFOpenFlowView *)self.view setNumberOfImages:10]; 
}

-(void)requestForImage:(NSUInteger)index{
    if(index>=[self.arX count]) return;
    ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[self.arX objectAtIndex:index]]];
    [req setDidFinishSelector:@selector(requestDone:)];
    [req setDidFailSelector:@selector(requestWentWrong:)];
    [req setUsername:[NSString stringWithFormat:@"%i",index]];
    [req setDelegate:self];
    [queue addOperation:req];   
    [queue go];
}

- (void)requestDone:(ASIHTTPRequest *)request
{   
    NSUInteger index=[[request username] intValue]; 
    UIImage *img=[UIImage imageWithData:[request responseData]];
    img=[img cropCenterAndScaleImageToSize:CGSizeMake(225, 225)];
    [(AFOpenFlowView*)self.view setImage:img forIndex:index];

    [self requestForImage:index+1];
     // here all requests are downloaded and you want display any msg to user that code goes here.

}

- (void)requestWentWrong:(ASIHTTPRequest *)request
{
//  NSError *error = [request error];
    NSUInteger index=[[request username] intValue];
    [self requestForImage:index+1];
}


- (void)imageDidLoad:(NSArray *)arguments {
    UIImage *loadedImage = (UIImage *)[arguments objectAtIndex:0];
    NSNumber *imageIndex = (NSNumber *)[arguments objectAtIndex:1];

    // Only resize our images if they are coming from Flickr (samples are already scaled).
    // Resize the image on the main thread (UIKit is not thread safe).
    loadedImage = [loadedImage cropCenterAndScaleImageToSize:CGSizeMake(225, 225)];

    [(AFOpenFlowView *)self.view setImage:loadedImage forIndex:[imageIndex intValue]];
}

- (UIImage *)defaultImage {
    return [UIImage imageNamed:@"default.png"];
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index{
    NSLog(@"request for index - %d",index);
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index {
    NSLog(@" Hello - Cover Flow selection did change to %d", index);
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
//    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

@end

Also Download code From Here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文