UIScrollView / Animation Update, Timing (Objective-C)

I have a UIScrollView that displays a list of data. Right now, when the user adds one more item to the list, I can expand the size of the contents of the UIScrollView and scroll smoothly using setContentOffset and YES to animate.

When the user removes an item from the list, I want to resize the contents of the UIScrollView and scroll back one step in an animated way too.

How can I get the right to order? Right now, if I resize the content before scrolling, the scrolling will not be animated.

I tried scrolling back until the content was resized, but it still did not give a smooth transition.

Is there a way to end the scroll animation BEFORE resizing the content?

thank

+3
source share
3 answers

Yes, you need to call a method to resize your content after the scroll animation has finished. This can be done in the delegate method scrollViewDidEndScrollingAnimation:. Set the controller as a delegate and implement this method.

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
     [scrollView setContentSize: newSize];
}

For this you do not need a timer or a table view.

+4
source

I think you should use UITablView and not UIScrollView.

in UITableView you can implement update functionality.

using single line code:

[tblView reloadData];
+1
source

, , - . , :

:

[scrollView setContentOffset:... animated:YES];
[NSTimer scheduledTimerWithTimeInterval:SECONDS_AS_FLOAT target:self selector:@selector(timerCallback:) userinfo:nil repeats:NO];

- (void)timerCallback:(NSTimer *)timer {
    // remove item from list at this point
    ...
    // set new content size
    [scrollView setContentSize];
}

You need to experiment to find out which correct SECONDS_AS_FLOAT time to use, it should be slightly longer than the scroll time. It will be on the order of several hundred milliseconds, so you can experiment with a value from 0.2 to 0.5.

0
source

Source: https://habr.com/ru/post/1740689/


All Articles