2014-09-15 3 views
0

맞춤로드 표시기를 만듭니다. 그래서,이탐색 후 애니메이션이 중지됩니다.

@property (nonatomic, readonly) CAShapeLayer *progressLayer; 
@property (nonatomic, readwrite) BOOL isAnimating; 

- (void)layoutSubviews { 
    [super layoutSubviews]; 

    self.progressLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)); 
    [self updatePath]; 
} 

- (void)updatePath { 
    CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 
    CGFloat radius = MIN(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2) - self.progressLayer.lineWidth/2; 
    CGFloat startAngle = 3 * M_PI_2; 
    CGFloat endAngle = self.endAngle; 
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 
    self.progressLayer.path = path.CGPath; 
} 

애니메이션처럼 내보기를 업데이트는

- (void)startAnimating { 
    if (self.isAnimating) 
    return; 

    CABasicAnimation *animation = [CABasicAnimation animation]; 
    animation.keyPath = @"transform.rotation"; 
    animation.duration = 1.0f; 
    animation.fromValue = @(0.0f); 
    animation.toValue = @(2 * M_PI); 
    animation.repeatCount = INFINITY; 

    [self.progressLayer addAnimation:animation forKey:kLLARingSpinnerAnimationKey]; 
    self.isAnimating = true; 
} 

- (void)stopAnimating { 
    if (!self.isAnimating) 
     return; 

    [self.progressLayer removeAnimationForKey:kLLARingSpinnerAnimationKey]; 
    self.isAnimating = false; 
} 

- (CAShapeLayer *)progressLayer { 
    if (!_progressLayer) { 
     _progressLayer = [CAShapeLayer layer]; 
     _progressLayer.strokeColor = self.tintColor.CGColor; 
     _progressLayer.fillColor = nil; 
     _progressLayer.lineWidth = 1.5f; 
    } 
    return _progressLayer; 
} 

내가 탭 표시 줄 응용 프로그램을 여기에서 시작되므로 애니메이션 시작, 내가 다른 탭을 클릭 한 다음 처음에 반환 할 때 문제입니다 내 사용자 지정 표시기가 움직이지 않습니다. 셀에 지표를 추가하면이 버그 (기능)가 콜렉션보기 셀에 나타납니다. 나는 간단한 방법 addSubview를 호출하여 내 표시기를 추가

[view addSubview:indicator]; 
[indicator startAnimating]; 

가 어떻게 탐색 한 후 정지 애니 메이팅을 방지 할 수 있습니까? 미리 감사드립니다.

다음
+0

TabBar 앱에서 한 뷰에서 다른 뷰로 이동하면 해당 뷰의 범위가 해제되어 objet가 활성 상태가됩니다. 또한 표시기의 기본 사용법은 서비스/작업이 완료 될 때까지 기다려야한다는 것을 사용자에게 알려주고 표시기가 완료 될 때까지 tabBar 선택 인덱스를 비활성화해야합니다. 나머지는 모두 응용 프로그램 사용에 따라 달라집니다. 추천 UI는 앱의 일부입니다. – nikhil84

+0

@ walle84하지만 UIActivityIndicatorView가 정상적으로 작동하고 멈추지 않는 이유는 무엇입니까? –

+0

이 줄이 보이지 않았습니다. "내 사용자 지정 표시기가 움직이지 않습니다.". 그렇다면 어떤 의미에서 움직이지 않습니까? – nikhil84

답변

0

가고,

는 // 나는 사용자가 한 tabBar 다른보기로 도청 동안 회 실행 중이거나하지 않은 경우 확인하기 위해 BOOL viewChange을 사용했다.

- (void)viewWillAppear:(BOOL)animated{ //On initial run the viewChange will be false and the condition in if won't run but as spinnerView start animating u could change the viewChange flag to true. 

    //So when user will be back from second view then this flag would be true and it will start animating. 

    //As your work is complete then just stop animating and remove from view. 

    if(viewChange){ 
    [spinnerView stopAnimating]; 
    [spinnerView removeFromSuperview]; 
    spinnerView = nil; 
    spinnerView = [[LLARingSpinnerView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 40, 40)]; 

    [self.view addSubview:spinnerView]; 
    [spinnerView startAnimating]; 
    } 
} 

- (void)viewWillDisappear:(BOOL)animated{ 

//This is called when user move from current view to another and at that point we user won't be seeing the spinnerView so remove it and release it only if it's animating. 

    if(spinnerView.isAnimating){ 
    viewChange = YES; 
    [spinnerView stopAnimating]; 
    [spinnerView removeFromSuperview]; 
    spinnerView = nil; 
    } 
    else{ 
    viewChange = NO; 
} 
} 

- (IBAction)stopBtn:(id)sender{  //Spinner is stop animating with tap on button and is removed from the view. 
    if(spinnerView.isAnimating){ 
     [spinnerView stopAnimating]; 
     [spinnerView removeFromSuperview]; 
     spinnerView = nil;    //release the obj of spinnerView. 
    } 
} 

- (IBAction)btnTap:(id)sender{   //Spinner is start animating with tap on button 
    if(!spinnerView) 
    spinnerView = [[LLARingSpinnerView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 40, 40)]; 
    spinnerView.lineWidth = 1.5f; 
    spinnerView.tintColor = [UIColor redColor]; 
    [self.view addSubview:spinnerView]; 

    [spinnerView startAnimating]; 
} 

의심의 여지가 있으면 알려주세요. 또한 가능한 경우 사용자가 다른보기로 이동하지 않도록해야합니다. 예를 들어 spinnerView가 실행 중일 때 일부 서비스 또는 업데이트가 실행 중이며 그 시점에서 사용자는 완료 될 때까지 다른보기로 이동해야합니다.

+0

큰 감사합니다! 그러나 컬렉션 뷰 셀에 대해서는 의문의 여지가 있습니다. 이 스피너를 셀에 추가하면 애니메이션이 중단됩니다. 분명한 해결책은 ViewWillAppear에서 reloadData를 호출하는 것입니다. 그러나 이것은 매우 효율적이지 않습니다. 너 walle84, 너 그것에 대해 어떻게 생각하니? –

+0

셀에 스피너를 사용하고 사용자가 다른보기로 이동할 수 있도록하는 것에 동의하지 않습니다. 그래서 당신은 다시 UR UI 부분에 생각해야합니다. 아직도 U가 그런 식으로 가고 싶다면, ur collectionView에 대한 더 자세한 정보는 나에게 UR 사용법에 대한 명확한 아이디어를 줄 것이다. 그런 다음 U 해결책/제안을 줄 수있을 것이다. – nikhil84

+0

이미지가 인터넷에서로드되는 동안 이미지 뷰가있는 셀에 스피너를 사용합니다. –

관련 문제