문제

인사말,

지도에 원을 그리려고합니다. 이 프로젝트의 모든 별도의 부분은 독립적으로 작동하지만 모두 합치면 모두 깨집니다.

내 ViewDidload에서 UI를 설정하여 대부분을 유지합니다.

그런 다음 터치 이벤트를 사용하여 새로 고침 맵 메소드를 호출합니다.

-(void)refreshMap{

NSString *thePath = [NSString stringWithFormat:@"http://maps.google.com/staticmap?center=%f,%f&zoom=%i&size=640x640&maptype=hybrid",viewLatitude, viewLongitude, zoom];
NSURL *url = [NSURL URLWithString:thePath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *mapImage = [[UIImage alloc] initWithData:data];

mapImage = [self addCircle:(mapImage) influence:(70) latCon:(320) lonCon:(320)];
NSLog(@"-- mapimageview retaincount %i",[mapImage retainCount]);    

mapImageView.image = mapImage;
[mapImage release];}

이와 같은 설정은 원으로 한 번 맵을로드하지만 맵이 다시 새로 고침되면 충돌이 발생합니다.

MapImage 릴리스에 주석을 달면 반복적으로 작동하지만 메모리 누출이 발생합니다.

내가 사용하고있는 부가 된 방법 :

-(UIImage *)addCircle:(UIImage *)img radius:(CGFloat)radius latCon:(CGFloat)lat lonCon:(CGFloat)lon{
int w = img.size.width;
int h = img.size.height; 
lon = h - lon;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

//draw the circle
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGRect leftOval = {lat- radius/2, lon - radius/2, radius, radius};
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 0.3);
CGContextAddEllipseInRect(context, leftOval);
CGContextFillPath(context);

CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);

return [UIImage imageWithCGImage:imageMasked];}

모든 통찰력/조언은 대단히 감사합니다!

도움이 되었습니까?

해결책

UIImage *mapImage = [[UIImage alloc] initWithData:data];
mapImage = [self addCircle:(mapImage) influence:(70) latCon:(320) lonCon:(320)];

그 좋지 않다. 두 번째 줄에서리스 디자인 할 때 MapImage의 내용에 대한 언급을 잃고 있습니다. 아마도 추가 변수를 추가하는 경우이 문제를 해결하는 가장 쉬운 방법은 두 이미지를 모두 추적 할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top