iphone setAnimationWillStartSelector / setAnimationDidStopSelector不工作(滚动代码示例)

StackOverflow https://stackoverflow.com/questions/1808320

  •  05-07-2019
  •  | 
  •  

我正在以水平滚动视图的形式在视图底部(想一想新闻频道的头条新闻标题栏)显示一个自动收报机。当我将repeatCount设置为无限时,它可以正常工作,但我希望能够在动画启动和停止时执行其他功能。但是,在网上阅读了文档和很多例子后,我无法得到setAnimationWillStartSelector / setAnimationDidStopSelector来响应。

这是我的代码:

- (void)animateView {    
[UIScrollView setAnimationDelegate:self];    
[UIScrollView setAnimationWillStartSelector:@selector(animationStart:context:)];    
[UIScrollView setAnimationDidStopSelector:@selector(animationStop:finished:context:)];    
[UIScrollView beginAnimations:@"pan" context:nil];    
[UIScrollView setAnimationDuration:10.0f];    
[UIView setAnimationRepeatCount:1];    
[UIView setAnimationBeginsFromCurrentState:YES];    
[UIScrollView setAnimationCurve:UIViewAnimationCurveLinear];    
tickerScrollView.contentOffset = CGPointMake(textLabelRect.size.width,0);    
[UIScrollView commitAnimations];    
}    
- (void)animationStart:(NSString *)animationID context:(void *)context {    
NSLog(@"animationWillStart");    
}
- (void)animationStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context {    
NSLog(@"animationDidStop");    
[self animateView];    
}

目前这段代码在我的UIViewController子类中。但是,我也尝试将它全部放在我的app委托中,同时也明显改变了setAnimationDelegate。我已尝试使用各种animationDurations,repeatCounts等,但仍然没有运气。

非常感谢任何帮助。感谢

有帮助吗?

解决方案

您可以尝试在动画块中放置setAnimationDelegate,setAnimationWillStartSelector和setAnimationDidStopSelector。根据iPhone OS参考库文档,这些方法必须放在动画块中才能使用。

希望这有帮助! 的AOB

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top