Fade in/out UIScrollView's content like Mobile Safari does in its tab

后端 未结 2 702
有刺的猬
有刺的猬 2021-01-30 11:44

NOTE: I added my new solution at the UPDATE answer below.

I try to recreate the effects we saw in Mobile Safari\'s tab on iPhone/iPod touch.

Ba

2条回答
  •  后悔当初
    2021-01-30 12:27

    As you'll have noticed from how often scrollViewDidScroll: is called, UIScrollView doesn't simply fire and forget a Core Animation transition: it manually moves the bounds according to touches, acceleration, etc. There's no straightforward way to change this.

    However, if you're being swamped by scroll events, you might try a trick like the following:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
        if (timestamp - _savedTimestamp) < 0.1)
            return;
        _savedTimestamp = timestamp;
    
        // do the rest of your work here
    }
    

    H

提交回复
热议问题