English 中文(简体)
在将遥感图像装入地图out布时的持久性问题
原标题:Perfomance issues when loading remote images in a map callout bubble

In my app I need to display stores around the user location. Each store has name, tagline, and a logo, and we want to display all these information on the callout bubble that comes up on the map once I touch a pin. Considering that I need to load the image remotely, and that waiting three seconds to see the callout after touching the pin is not acceptable, what would be the best solution? The file of an array of around 20 stores is like 10kb, but if we load the logo for all of them straight away, maybe it would be like 110kb (considering an estimate of 5kb per image), which I`m not sure if it is a good idea.

最佳回答

In one of my project that case works just fine. I m using SDWebImage for the remote async load of the image.

我这样做了:

MKPinAnnotation 观点:

页: 1

@interface TLStoreResultMapAnnotationView : MKPinAnnotationView

@property (assign)BOOL imageSet;

@end

.m

#import "TLStoreResultMapAnnotationView.h"
#import "TLStoreResultMapAnnotation.h"
#import "UIImageView+WebCache.h"

@implementation TLStoreResultMapAnnotationView
@synthesize imageSet=_imageSet;

- (void)layoutSubviews {

    if(self.selected && (!self.imageSet)) {
        TLStoreResultMapAnnotation *annotation = (TLStoreResultMapAnnotation *)self.annotation;

        NSURL *url = [NSURL URLWithString:[annotation.store.imageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

        UIImageView *storeImageView = (UIImageView *)self.leftCalloutAccessoryView;
        storeImageView.frame = CGRectMake(storeImageView.frame.origin.x,storeImageView.frame.origin.y,30.0,30.0);
        storeImageView.contentMode = UIViewContentModeScaleAspectFill;
        storeImageView.clipsToBounds = YES;
        [storeImageView setImageWithURL:url
                  placeholderImage:[UIImage imageNamed:@"webloading.png"] options:SDWebImageCacheMemoryOnly];


        self.imageSet = YES;
    }

    [super layoutSubviews];
    UIImageView *storeImageView = (UIImageView *)self.leftCalloutAccessoryView;
    storeImageView.frame = CGRectMake(storeImageView.frame.origin.x,storeImageView.frame.origin.y,30.0,30.0);
}

@end

当然,你需要使该守则变成一条轨道。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签