iphone setAnimationWillStartSelector / setAnimationDidStopSelectorが機能しない(スクロールティッカーの例)
-
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サブクラスにあります。ただし、setAnimationDelegateも明らかに変更しながら、すべてをアプリのデリゲートにも入れてみました。さまざまなanimationDurations、repeatCountsなどを使用してみましたが、それでも運はありません。
ご協力いただければ幸いです。ありがとう
解決
setAnimationDelegate、setAnimationWillStartSelector、setAnimationDidStopSelectorをアニメーションブロック内に配置してみてください。 iPhone OSリファレンスライブラリのドキュメントによると、これらのメソッドを機能させるには、アニメーションブロック内に配置する必要があります。
これがお役に立てば幸いです! aobs
所属していません StackOverflow