2012-07-20 3 views
3

내 이미지보기 애니메이션에 큰 지연이 있습니다.이미지 배열의 애니메이션 지연

탐색 기반 응용 프로그램을 만들고 있습니다.

내 세 번째보기 컨트롤러의 viewDidLoad에서 이미지보기를 만들고 하위보기로 추가했습니다.

self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(259, 46, 496, 470)]; 
self.myImageView.image = [UIImage imageNamed:@"foo.png"]; 
[self.view addSubview:self.myImageView]; 

버튼을 클릭하면 하나의 애니메이션에서 다른 애니메이션으로 myImageView를 전환하고 싶습니다.

이미지의 애니메이션 배열이 두 개인 경우 viewDidLoad에서 초기화되지만 [self.myImageView startAnimating] 호출시 약간의 지연이 발생합니다. 처음으로. 내 버튼

제가 아래로 내 이미지보기 애니메이션 클릭 다음 버튼 누름에

self.myImageView.animationImages = self.openAnimationArray; 
    [self.myImageView startAnimating]; 
    self.myImageView.animationRepeatCount = 0; 

저는 이미지 어레이의 또 다른 세트와 동일한 이미지 뷰 애니메이션. 난이 초기화 지연을 피하기 위해 세 번째보기 controller.In 순서로 이동하고 closeAnimationArray 및 openAnimationArray 앱 위임 [UIApplication sharedApplication]에 저장하면서 .delegate

self.myImageView.animationImages = self.closeAnimationArray; 
[self.myImageView startAnimating]; 
self.myImageView.animationRepeatCount = 0; 

내 첫번째 문제점은 지연되었다.

이 지연은 처음으로 세 번째보기 컨트롤러로 이동하는 경우에만 발생합니다. 나는 그것이 이미지 캐싱으로 인한 것일 수 있다고 생각한다. 두 번째 navigation.UIImage imageNamed 함수에서 이미지를 캐싱하는 데 지연이 없다. 첫 번째 탐색에서 지연을 피하기 위해 강제로 앱 위임자의 이미지를로드했습니다. 힘 로딩

NSArray * openAnimationArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],[UIImage imageNamed:@"5.png"], nil]; 
    for (id object in openAnimationArray) 
    { 

     [object forceLoad]; 

    } 

방법은 아래와 같습니다 :

- (void) forceLoad 
{ 
    const CGImageRef cgImage = [self CGImage]; 

    const int width = CGImageGetWidth(cgImage); 
    const int height = CGImageGetHeight(cgImage); 

    const CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage); 
    const CGContextRef context = CGBitmapContextCreate(
                 NULL, 
                 width, height, 
                 8, width * 4, 
                 colorspace, kCGImageAlphaNoneSkipFirst); 

    CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage); 
    CGContextRelease(context); 
} 

하지만 여전히 처음 animation.It의 지연이 매우 심하게 내 응용 프로그램의 성능에 영향을 미칩니다. 어떻게하면이 문제를 해결할 수 있습니다.

+0

참조 http://stackoverflow.com/a/17225223/763355 – MoDJ

답변

0

이 시도 :

NSArray * openAnimationArray = [NSArray arrayWithObjects:[UIImage initWithContentsOfFile:@"1.png"],[UIImage initWithContentsOfFile:@"2.png"],[UIImage initWithContentsOfFile:@"3.png"],[UIImage initWithContentsOfFile:@"4.png"],[UIImage initWithContentsOfFile:@"5.png"], nil]; 

UIImage initWithContentsOfFile:@"2.png"][UIImage imageNamed:@"2.png"]보다 빠릅니다. 캐시를 사용하지 않고 이미지를로드하기 때문입니다.

+0

그것은 나를 위해 작동합니다. 이 [링크] (http://stackoverflow.com/questions/7525348/uiimage-initwithcontentsoffile-doesnt-work)로 'initWithContentsOfFile'을 사용하십시오. – Kerberos