Reputation: 33421
Getting the page curl animation to work is easy:
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[transition setDuration:0.5f];
[transition setType:@"pageCurl"];
[transition setSubtype:landscape ? @"fromBottom" : @"fromRight"];
[self.view.layer addAnimation:transition forKey:@"CurlAnim"];
However, my boss wants me to make it turn from the middle (like in iBooks) when in landscape. I can't use UIPageViewController
because I need to scroll two pages in portrait also, as well as zooming in on the two pages at once in landscape and scrolling. Is there some way to do this? Right now it just curls the entire view like a giant landscape page. Since it uses two layers, I doubt there is an easy way to do it, but I thought I'd ask.
Upvotes: 0
Views: 710
Reputation: 53341
Still thinking about this, if you force the UIPageViewController to show 2 pages in both landscape and portrait, and put it inside the UIScrollerView. When you are in landscape it shows the 2 pages, zoom and work as expected. If you are in portrait, you can make the UIPageViewController frame.width to be the double of a single page, and the UIScrollerView contentSize the same width the UIPageViewController, but the UIScrollerView frame width the same width a page. Doing this you show only a page and can scroll to the second. I have tested and works fine on landscape, but have some problems in portrait, the swipe to change page doesn't work from inside, but this works from outside (that's why I set the _zoomer.frame = CGRectMake(10,10,widht,height), to have a 10 points frame arround the UIPageViewController to swipe from there), the tap to change page works too.
The code I use on the screen rotation, and for iPad only.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
CGRect pageViewRect;
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
pageViewRect = CGRectMake(0,0,1496,984);
_zoomer.contentSize=CGSizeMake(1496, 984);
_zoomer.frame = CGRectMake(10,10,748,984);
self.pageViewController.view.frame = pageViewRect;
} else {
pageViewRect = CGRectMake(0,0,1004,728);
_zoomer.frame = CGRectMake(10,10,1004,728);
_zoomer.contentSize=CGSizeMake(1004, 728);
self.pageViewController.view.frame = pageViewRect;
}
}
_zoomer is the UIScrollerView
Upvotes: 0
Reputation: 53341
And you can't use the UIPageViewController inside a UIScrollerView?
Doing this you can zoom in/out both pages.
The only problem is, you can't change the page unless you have zoom = 1
Upvotes: 1