简体   繁体   中英

Using the “swipe to go back” gesture in my own app

I'm building an iOS application that requires the same effect seen when swiping back and forth in Safari.

When swiping to go back, the foreground panel moves out of the way but the panel in the back is moving a bit as well. Very similar to the horizontal scrolling that exists in the Yahoo Weather app.

Is this a built-in control with iOS 7? I'm seeing it in a lot of places but can't quite figure out how to do it.

I think there are 2 UIScrollView working together, when the user scrolls on the foreground UIScrollView , you should move the background UIScrollView , something like this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:self.scrollViewForeground]) {

        CGPoint offset = self.scrollViewForeground.contentOffset;
        offset.x = offset.x * 0.5;
        [self.scrollViewBackground setContentOffset:offset];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM