Animate scrolling of UIScrollView with CoreAnimation

后端 未结 4 500
醉酒成梦
醉酒成梦 2021-02-07 09:24

Sorry for a big question, real question are bold in bottom, now some explanation.

I\'m use CoreAnimation in my project for animate some objects moving l

相关标签:
4条回答
  • 2021-02-07 10:14

    You could use:

    [UIView animateWithDuration:duration animations:^ {
        [scrollView setContentOffset:destination animated:NO];
    }];
    

    You can set the duration of the animation this way.

    0 讨论(0)
  • 2021-02-07 10:15
    [UIScrollViewNameHere setContentOffset:CGPointMake(x value of where you want to move to, y value of where you want to move to) animated:YES];
    

    for example:

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(4, 2, 2341, 412)];
    [scroll setContentOffset:CGPointMake(320, 0) animated:YES];
    
    0 讨论(0)
  • 2021-02-07 10:25

    I don't think so that you can animate the point with CoreAnimation.

    But you can try setContentOffset:animated: thats the method you are searching for?

    You can transform only following properties of UIView

    • frame
    • bounds
    • center
    • transform
    • alpha
    • backgroundColor
    • contentStretch

    more Information of the CoreAnimation about animation checkout the Apple Documentation

    0 讨论(0)
  • 2021-02-07 10:27

    You should read about animatable properties, Programming iOS 5

    Indeed, when you try to animate layers, Apple gives a set of animatable properties, but you're not limited to this set. You can animate whatever you want.

    In all cases, you shouldn't use kCAFillModeForwards because it will ask the device to redraw forever the last presentation layer that was used for the animation, instead of using a cached representation of the layer.

    So the way you could achieve such a thing would be by defining a specific layer of yours where the contentOffset property is defined as animatable. And in order to work, you should start by verifying what kind of top layer class is used by a scrollview, so that, by subclassing it and setting the wanted property (contentOffset) animatable, and subclassing your scrollview by setting this layer as the top layer of the scrollview, you could possibly achieve what you're trying to do.

    This is theory!

    But this is what I would try. Look for this method and its behavior and intents

    + (BOOL)needsDisplayForKey:(NSString *)key
    

    Another thing you could read is this A start example. But this also means you should redraw your uiscrollview by yourself!

    0 讨论(0)
提交回复
热议问题