Soft scroll animation NSScrollView scrollToPoint:

前端 未结 5 1347
旧巷少年郎
旧巷少年郎 2021-02-13 23:53

I want to create soft animation between transitions in simply UI:

\"first

5条回答
  •  爱一瞬间的悲伤
    2021-02-14 00:24

    scrollToPoint is not animatable. Only animatable properties like bounds and position in NSAnimatablePropertyContainer are animated. You don't need to do anything with CALayer: remove the wantsLayer and CALayer stuff. Then with following code it is animated.

    - (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];
    }
    

提交回复
热议问题