简体   繁体   中英

How to synchronise UIView moving with swipe gesture of UIPageViewController

Ok, here is the thing:

I need to have few animations happening on every screen change in my PageViewController.

So, when a user swipes, an image should fly in from the top left corner, from example.

I can make that animation to happen over time when user swipes and changes the page, but what I need is to that animation to be synchronised with the swipe movement itself. So if a user presses the screen and starts swiping, the animation should follow user's finger and animate it's translation with the finger movement.

How can I achieve that? I guess I need some sort of swipe gesture listener, but I failed to find any solution online. I guess I'm not using the right keywords.

You can use a UIPanGestureRecognizer to get the number of pixels swiped:

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognizer_Panned:)];
[self.myViewToSwipe addGestureRecognizer:panRecognizer];

...

- (void) panRecognizer_Panned:(UIPanGestureRecognizer *)recognizer {
    CGFloat pixelsMovedHoriz = [recognizer translationInView:self.vwRelativeTo].x;
}

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