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

use*_*485 2 iphone uiscrollview

我正在以水平滚动视图的形式在视图的底部(想想新闻频道的标题标题栏)显示一个自动收报机.当我将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];    
}
Run Code Online (Sandbox Code Playgroud)

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

非常感谢任何帮助.谢谢

aob*_*obs 6

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

希望这可以帮助!AOB的