Pregunta

I'm trying to implement a moving background picture behind a UIPageView in a panoramic way. (similar to the concept of an android home screen)

The PageView has the transistion style "Scroll".

All I found until now was using the delegate "didFinishAnimation" method:

(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed

With this method the background moves just after the new page has been reached. I would like it to happen simultaneously.

Is there any way to synchronize the position of this imageview with the current dragging position of the page view?

¿Fue útil?

Solución

Granted it's kind of hacky but in iOS 7.1, the page view controller's scroll view has no delegate by default, and you can become its delegate without accessing any private API. Subclass UIPageViewController, and in your subclass call

- (void)viewDidLoad {
    [super viewDidLoad];
    // other code
    NSInteger scrollViewIdx = [self.view.subviews indexOfObjectPassingTest:^BOOL(UIView *subview, __unused NSUInteger idx, __unused BOOL *stop) {
        return [subview isKindOfClass:UIScrollView.class];
    }];
    NSAssert(scrollViewIdx != NSNotFound, @"Failed to find page view controller scroll view");
    UIScrollView *scrollView = self.view.subviews[scrollViewIdx];
    scrollView.delegate = self; // or whatever
}

then you can implement

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top