12

単純な UI でトランジション間にソフト アニメーションを作成したい:

最初のスライド2 番目のスライド3番目のスライド

移動したビュー

見る

scrollToPoint: for move view to point を呼び出すと、そのトランジションはアニメーション化されません。私は Cocoa プログラミングの初心者です (iOS は私のバックグラウンドです)。そして、.animator または NSAnimationContext を正しく使用する方法がわかりません。

また、コア アニメーション ガイドを読みましたが、解決策が見つかりませんでした。

ソースはGit Hub リポジトリでアクセスできます

助けてください !!!

4

5 に答える 5

24

scrollToPoint はアニメーション化できません。NSAnimatablePropertyContainer の境界や位置などのアニメーション可能なプロパティのみがアニメーション化されます。CALayer で何もする必要はありません。wantsLayer と CALayer のものを削除してください。次に、次のコードでアニメーション化します。

- (void)scrollToXPosition:(float)xCoord {
    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:5.0];
    NSClipView* clipView = [_scrollView contentView];
    NSPoint newOrigin = [clipView bounds].origin;
    newOrigin.x = xCoord;
    [[clipView animator] setBoundsOrigin:newOrigin];
    [_scrollView reflectScrolledClipView: [_scrollView contentView]]; // may not bee necessary
    [NSAnimationContext endGrouping];
}
于 2013-10-17T10:48:03.690 に答える
6

この回答のSwift 4コード

func scroll(toPoint: NSPoint, animationDuration: Double) {
    NSAnimationContext.beginGrouping()
    NSAnimationContext.current.duration = animationDuration
    let clipView = scrollView.contentView
    clipView.animator().setBoundsOrigin(toPoint)
    scrollView.reflectScrolledClipView(scrollView.contentView)
    NSAnimationContext.endGrouping()
}
于 2018-04-05T12:21:08.420 に答える