2014-03-07 2 views
1

이 메서드를 사용하여 자리 표시 자에서 활동 표시기를 수행하려면 어떻게해야합니까?SDWebImage 클래스

- (void)createActivityIndicatorWithStyle:(UIActivityIndicatorViewStyle) activityStyle { 

if ([self activityIndicator] == nil) { 
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:activityStyle]; 

    self.activityIndicator.autoresizingMask = UIViewAutoresizingNone; 

    //calculate the correct position 
    float width = self.activityIndicator.frame.size.width; 
    float height = self.activityIndicator.frame.size.height; 
    float x = (self.frame.size.width/2.0) - width/2; 
    float y = (self.frame.size.height/2.0) - height/2; 
    self.activityIndicator.frame = CGRectMake(x, y, width, height); 

    self.activityIndicator.hidesWhenStopped = YES; 
    [self addSubview:self.activityIndicator]; 
} 

[self.activityIndicator startAnimating]; 

}

나는 당신이이 방법을 수행 할 수 있습니다

+0

너는 지표를 넣는가? UIImageView 무엇입니까? – simalone

+0

예이 작업을 수행하고 표시기를 UIImageView 자리 표시 자에 넣어야합니다. –

+0

SDWebImage의 오픈 소스를 수정해야합니다. 받아 들일 수 있습니까? – simalone

답변

1

어떤 도움을 주셔서 감사합니다, 나는 세포를 업데이트이 예에서 사용하지만, 어떤 당신이 필요로 사용하는 것은 동일합니다.

내가하고있는 일은 UIImageView 알파를 0으로 설정하고, UIActivityIndicatore를 추가하고, 이미지가로드 될 때 알림을 받기 위해 블록을 호출하는 것입니다. 로드되면 UIImageView 알파가 다시 1로 설정되고 UIActivityIndicator가 제거됩니다.

-(void)updateCell { 

self.imageView = [[UIImageView alloc]initWithFrame:frameOfCell]; 
self.imageView.alpha = 0; 
[self addSubview:self.imageView]; 

//Activity indivator: 
self.activity= [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
self.activity.hidesWhenStopped = YES; 
self.activity.frame = CGRectMake((frameOfCell.size.width/2)-10, (frameOfCell.size.height/2)-20, 40, 40); 
[self.activity startAnimating]; 
[self addSubview:self.activity]; 



[self.imageView setContentMode:UIViewContentModeScaleAspectFit]; 
NSURL *urlOfImage = [NSURL URLWithString:self.imageName]; 
self.imageView.alpha = 0; 


[self.imageView setImageWithURL:urlOfImage completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { 
    /// 
    self.imageView.alpha = 1; 

    //Removing activity indicator: 

    [self.activity stopAnimating]; 
    [self.activity removeFromSuperview]; 


}]; 

} 

희망이

1

여기에 도움이 당신이해야 할 사항은 다음과 같이 코드를 수정 UIActivityIndicatorView

시도로 UIProgressView을 변경하는 것입니다 a Category on UIImageView, adding a progress view while images are downloaded using SDWebImage.

입니다 :

- (void)removeIndicatorView{ 
    [self.activityIndicator stopAnimating]; 
} 

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock withActivityStyle:(UIActivityIndicatorViewStyle) activityStyle { 
    [self createActivityIndicatorWithStyle:activityStyle]; 

    __weak typeof(self) weakSelf = self; 

    [self setImageWithURL:url 
     placeholderImage:placeholder 
        options:options 
       progress:^(NSUInteger receivedSize, long long expectedSize) { 
        //If you don't care progress, do nothing 
       } 
       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { 
        [weakSelf removeIndicatorView]; 
        if (completedBlock) { 
         completedBlock(image, error, cacheType); 
        } 
       } 
    ]; 
} 
관련 문제