私はテキストビューを自動的にスクロールし、最後に到着したらトップに戻そうとしています。自動スクロールUITextView問題
私はこのコードを使用します。その結果
-(void)scrollTextView
{
CGPoint scrollPoint = stationInfo.contentOffset;
scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 2);
if (scrollPoint.y == originalPoint.y + 100)
{
NSLog(@"Reset it");
scrollPoint = CGPointMake(originalPoint.x, originalPoint.y);
[stationInfo setContentOffset:scrollPoint animated:YES];
[scroller invalidate];
scroller = nil;
scroller = [NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(scrollTextView)
userInfo:nil
repeats:YES];
}
else
{
[stationInfo setContentOffset:scrollPoint animated:YES];
}
}
を、テキストビューは乱暴周りにジャンプしますが、私はかなり理由を知りません。テキストビューが最下部にあることを検出するより良い方法はありますか? scrollPoint
の値を間違って設定していますか?
編集:
問題が解決しました!私はNSTimerに固執しました - 欠けているキーはレイヤーのために-display
を呼び出していました。
-(void)scrollTextView
{
//incrementing the original point to get movement
originalPoint = CGPointMake(0, originalPoint.y + 2);
//getting the bottom
CGPoint bottom = CGPointMake(0, [stationInfo contentSize].height);
//comparing the two to detect a reset
if (CGPointEqualToPoint(originalPoint,bottom) == YES)
{
NSLog(@"Reset");
//killing the timer
[scroller invalidate];
scroller == nil;
//setting the reset point
CGPoint resetPoint = CGPointMake(0, 0);
//reset original point
originalPoint = CGPointMake(0, 0);
//reset the view.
[stationInfo setContentOffset:resetPoint animated:YES];
//force display
[stationInfo.layer display];
scroller = [NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(scrollTextView)
userInfo:nil
repeats:YES];
}
else
{
[stationInfo setContentOffset:originalPoint animated:YES];
}
}
コールバックメソッドのシグネチャが間違っています。私の答えを見て、正しいものを見てください。 – GorillaPatch
このコードは正常に動作します。これは非常に低レベルのコードであることに気をつけてください。 CoreAnimationは本当に簡単になりました。私は、ドキュメントを読むのには時間がかかることは認めていますが、それはそれだけの価値があります。 1つの質問が残っています。なぜあなたはCALayerと直接対話しますか?あなたが直接層を扱っていないので(あるいはあなたに)私は[stationInfo setNeedsDisplay]と呼ぶでしょう。 – GorillaPatch
なぜコンテンツのオフセットをアニメーションに設定するのですか?あなたはあなたのタイマーでアニメートしているので、私は各2ピクセルステップのアニメーションを使用しません。本当の問題は、あなたがそこでトリガーしている陰的なアニメーションが0.1タイムステップよりも長くなっていることです。これは物事をひどく混乱させるでしょう。下にスクロールするときにアニメーションなしで設定してください。また、CALayerのディスプレイコールを省略することもできますが、これはまだ私には奇妙に見えます。 – GorillaPatch