2009-11-27 70 views
2

我在水平滚动视图的形式下在视图底部显示一个股票代码(想想新闻频道的头条滚动条)。当我将repeatCount设置为无限时,它正常工作,但我希望在动画启动和停止时能够执行一些其他功能。但是,在阅读了文档和在线许多示例之后,我无法获取setAnimationWillStartSelector/setAnimationDidStopSelector作出响应。iphone 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子类。不过,我也尝试将它全部放在我的应用程序委托中,同时也明显改变了setAnimationDelegate。我试过使用各种animationDurations,repeatCounts等,但仍然没有运气。

真的很感激任何帮助。谢谢

+0

忽略UIView/UIScrollView调用,上面的代码只是一个不同的方法,我尝试过,我忘记在复制它之前改变它,但它没有任何区别,所以只需将它们全部归类为UIView调用与你的答案有什么不同。谢谢 – user218485 2009-11-30 10:20:33

回答

6

您可以尝试在动画块中放置setAnimationDelegate,setAnimationWillStartSelector和setAnimationDidStopSelector。根据iPhone操作系统参考库文档,这些方法必须放在动画块中以使其工作。

希望这会有所帮助! aobs