I m using UIPageViewController on iPad where I need to show a firstviewController in the first page and ContentViewController in the next page in landscape.
If I set the NSArray with two viewControllers the app is crashes at [self.pagviewController setViewController:] with the following exception:
The number of provided view controllers (2) doesn't match the number required (1) for the requested spine location (UIPageViewControllerSpineLocationMin)
Below is the code:
#pragma mark - UIPageViewControllerDataSource Methods
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController textContents]];
if(currentIndex == 0)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.textContents = [self.modelArray objectAtIndex:currentIndex - 1];
return contentViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController textContents]];
if(currentIndex == self.modelArray.count-1)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.textContents = [self.modelArray objectAtIndex:currentIndex + 1];
return contentViewController;
}
//#pragma mark - UIPageViewControllerDelegate Methods
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if(UIInterfaceOrientationIsPortrait(orientation))
{
//Set the array with only 1 view controller
UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
//Important- Set the doubleSided property to NO.
self.pageViewController.doubleSided = NO;
//Return the spine location
return UIPageViewControllerSpineLocationMin;
}
else
{
NSArray *viewControllers = nil;
ContentViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)currentViewController textContents]];
if(currentIndex == 0 || currentIndex %2 == 0)
{
UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil];
}
else
{
UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
}
//Now, set the viewControllers property of UIPageViewController
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
return UIPageViewControllerSpineLocationMid;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
//Instantiate the model array
self.modelArray = [[NSMutableArray alloc] init];
self.vcs = [[NSMutableArray alloc]init];
for (int index = 1; index <= 2 ; index++)
{
[self.modelArray addObject:[NSString stringWithFormat:#"Page %d",index]];
}
//Step 1
//Instantiate the UIPageViewController.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
//Step 2:
//Assign the delegate and datasource as self.
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
//Step 3:
//Set the initial view controllers.
appDelegate.contentViewController.textContents = [self.modelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObjects:appDelegate.firstViewController,appDelegate.contentViewController,nil];
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
//Step 4:
//ViewController containment steps
//Add the pageViewController as the childViewController
[self addChildViewController:self.pageViewController];
//Add the view of the pageViewController to the current view
[self.view addSubview:self.pageViewController.view];
//Call didMoveToParentViewController: of the childViewController, the UIPageViewController instance in our case.
[self.pageViewController didMoveToParentViewController:self];
//Step 5:
// set the pageViewController's frame as an inset rect.
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pageViewController.view.frame = pageViewRect;
//Step 6:
//Assign the gestureRecognizers property of our pageViewController to our view's gestureRecognizers property.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}
The problem is you passing an array containing two view controllers to the page view controller while it expects one at a time, change your array to be like this :
NSArray *viewControllers = #[appDelegate.firstViewController];
You will pass one of the views but viewControllerAfterViewController and viewControllerBeforeViewController will handle the rest.
Ah..Finally got solution for this same issue.., it may helps you..
When we set the spine location to UIPageViewControllerSpineLocationMid, the doubleSided property of the pageViewController is automatically set to YES. This means that the content on page front will not partially show through back. But when this property is set to NO, the content on page front will partially show through back, giving the page a translucent kind of effect. So, in the portrait orientation, we have to set the value to NO, otherwise it would result in an exception.
So in your UIPageviewcontroller delegate method, in else part add this doubleSided property as YES when you return spineLocation as UIPageViewControllerSpineLocationMid
self.pageViewController.doubleSided = YES;
return UIPageViewControllerSpineLocationMid;
self.pageViewController.doubleSided = NO;
return UIPageViewControllerSpineLocationMid;
This is the solution for the exception.
In xcode it self you could find this.
Go to the UIPageViewcontroller class there you could see the explanation for this like:
#property (nonatomic, readonly) UIPageViewControllerSpineLocation spineLocation; // If transition style is 'UIPageViewControllerTransitionStylePageCurl', default is 'UIPageViewControllerSpineLocationMin', otherwise 'UIPageViewControllerSpineLocationNone'.
// Whether client content appears on both sides of each page. If 'NO', content on page front will partially show through back.
// If 'UIPageViewControllerSpineLocationMid' is set, 'doubleSided' is set to 'YES'. Setting 'NO' when spine location is mid results in an exception.
#property (nonatomic, getter=isDoubleSided) BOOL doubleSided; // Default is 'NO'.
Instead of implementing a full data source, you can set the PageViewController with one view controller at a time each time the user pushes a next or back button, like
[pageViewController setViewControllers:#[contentViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
This will animate the page transition as you switch.
Related
How does one ensure that the viewWillAppear: and viewDidAppear: (and other view transition methods) are called on a UIPageViewController's child ViewControllers?
In my case, the view transition methods are adequately called on all except for the very firstViewController that the UIPageViewController opens to. On that firstViewController, the viewDidAppear: and viewWillAppear: methods are actually called BEFORE the UIPageViewController's view transition methods. And then as one starts scrolling, the viewWillAppear: and viewDidAppear: methods are called as one would expect for the new view controllers.
Here is my structure: I have a BossViewController that contains an OrganizerViewController (a couple different organizers, actually, but that is irrelevant). The OrganizerViewController contains a UIPageViewController, which contains a series of CustomViewControllers. My code adequately calls the child view transition methods as per apple (https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html) for the interactions between the BossViewController and the OrganizerViewController (fully functional, perfectly so). The problem lies somewhere between the OrganizerViewController, it's child UIPageViewController, and it's first child CustomPageViewController.
I have tried calling beginAppearanceTransition: and endAppearanceTransition: within the UIPageViewController's viewWillAppear: and viewDidAppear: - but that resulted in an 'unbalanced calls' error log to console.
Here is the UIPageViewController set up code, all of which is in the OrganizerViewController:
- (void)configurePVC
{
NSDictionary *key = #{UIPageViewControllerOptionInterPageSpacingKey : #([UIScreen mainScreen].bounds.size.width * 0.5)};
_pvc = [[AVSCustomPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:key];
self.pvc.delegate = self;
self.pvc.dataSource = self;
_pvcArray = [[NSMutableArray alloc] init];
CustomViewController *daily = (CustomViewController *)[self viewControllerAtIndex:6];
self.index = 6;
[self.pvcArray addObject:daily];
[self.pvc setViewControllers:self.pvcArray
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
[self addChildViewController:self.pvc];
[self.dailyContainerView addSubview:self.pvc.view];
self.pvc.view.frame = self.dailyContainerView.bounds;
[self.pvc didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(CustomViewController *)viewController index];
if (index == 0) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(CustomViewController *)viewController index];
if (index == 6) {
return nil;
}
index++;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
CustomViewController *viewController = [[CustomViewController alloc] init];
viewController.index = index;
return viewController;
}
I want to build swipe navigation like the one shown in these pics. There are total 4 headings placed horizontally.
swipe navigation
They are as follows.
"History"
"Rules"
"PRO"
"Terms And Conditions"
If i am reading "History" & swipe from right to left, then the "Rules" should be displayed.
And if am on "Rules", and swipe from left to right then it should display "History"
Can anyone please guide me how to do this ?
Thanks.
The link you posted is a static screenshot, and not very helpful in describing what you want to do.
I think what you are describing is a normal behavior for a UIPageViewController, set up for a slide transition rather than a page curl transition.
Do a search on "PhotoScroller" in Xcode. That will point to a demo app that illustrates the effect I think you are after. That app is more complex than you need as it supports pinch zooming and tiled rendering of pictures, but you can ignore that stuff.
I too would recommend a UIPageViewController. Here is a bare bones implementation:
#interface SwipeViewController : UIViewController <UIPageViewControllerDataSource>
#property (nonatomic, strong) UIPageViewController *pageViewController;
#property (nonatomic, strong) NSArray <UIViewController*> *viewControllers;
#end
#implementation SwipeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// add page view controller
[self.pageViewController willMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
// set the first view controller as the displayed view controllers (requires an array of exactly one view controller)
[self.pageViewController setViewControllers:#[self.viewControllers.firstObject] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
// array of 4 random colored view controllers
- (NSArray <UIViewController*>*)viewControllers {
if (!_viewControllers) {
_viewControllers = ({
NSMutableArray *viewControllers = [NSMutableArray new];
for (int i = 0; i < 4; i++) {
UIViewController *aViewController = [UIViewController new];
aViewController.view.backgroundColor = [UIColor colorWithRed:(arc4random()%255)/255. green:(arc4random()%255)/255. blue:(arc4random()%255)/255. alpha:1];
[viewControllers addObject:aViewController];
}
viewControllers;
});
}
return _viewControllers;
}
- (UIPageViewController *)pageViewController {
if (!_pageViewController) {
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
_pageViewController.dataSource = self;
}
return _pageViewController;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index > 0 ? self.viewControllers[index-1] : nil;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index + 1 < self.viewControllers.count ? self.viewControllers[index+1] : nil;
}
#end
I have a UIPageViewController that I've set up with an array as the datasource. I see the first page fine and the presentation count dots show up correctly, but when I try to drag the to the next page nothing happens. So I set up some breakpoints in the viewControllerAfterViewController as well as Before methods and they never get called on. The other dataSource methods for presentationCountForPageViewController get called on fine.
Any idea what I am missing? I've been going line by line with examples I've found on the web but can't find anything.
- (void)viewDidLoad
{
[super viewDidLoad];
UIPageViewController *pageController = self.pageController;
pageController.dataSource = self;
UIChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:pageController];
[self.view addSubview:pageController.view];
[pageController didMoveToParentViewController:self];
}
- (UIPageViewController *)pageController
{
return !_pageController ? _pageController =
({
UIPageViewController *value = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
value.view.frame = self.view.bounds;
value;
}) : _pageController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pa geViewController viewControllerBeforeViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
return (index == 0 ) ? nil : [self viewControllerAtIndex:--index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
index++;
return (index == self.myDataSourceArray.count) ? nil : [self viewControllerAtIndex:index];
}
- (UIChildViewController *)viewControllerAtIndex:(NSUInteger)index
{
UIChildViewController *childViewController = [UIChildViewController new];
childViewController.view.frame = self.pageController.view.bounds;
childViewController.index = index;
...
return childViewController;
}
- (NSInteger)presentationCountForPageViewController: (UIPageViewController *)pageViewController
{
// The number of items reflected in the page indicator.
return self.myDataSourceArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UI PageViewController *)pageViewController
{
// The selected item reflected in the page indicator.
return 0;
}
The problem was that in including my UIViewController subclass which encapsulated the UIPageViewController, I forgot in the parent view controller's viewDidLoad to include addChildViewController and didMoveToParentViewController
[self addChildViewController:myViewController];
[self.view addSubview:myViewController.view];
[myViewControllerController didMoveToParentViewController:self];
Fixed the problem.
I am doing a tutorial in my iOS app. But I have a bug in my PageViewController.
My tutorial has 5 pages. But the second movement that I do to change page always appears the previous page repeatedly.
For example, appears page0, move to page1, and then when i want to appear page2, appears page1 again.
This occurs to both sides.
This is my code:
- (void)viewDidLoad {
[super viewDidLoad];
self.pageTexts = #[#"",intro1, intro2, intro3, intro4];
self.index = 0;
self.viewControllerPageContentOne = [[ViewControllerPageContentOne alloc] init];
self.viewControllerPageContentTwo = [[ViewControllerPageContentTwo alloc] init];
self.viewControllerPageContentThree = [[ViewControllerPageContentThree alloc] init];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
UIViewController* first = [self viewControllerUsed];
NSArray *viewControllers = [NSArray arrayWithObject:first];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (UIViewController *)viewControllerUsed{
if (self.index == 0) {
self.viewControllerPageContentOne=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentOne"];
return self.viewControllerPageContentOne;
}
else if (self.index == 1)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 2)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 3)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 4)
{
self.viewControllerPageContentThree=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentThree"];
self.viewControllerPageContentThree.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentThree;
}
else{
return nil;
}
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
self.index--;
if (self.index < 0) {
self.index = [self.pageTexts count]-1;
}
return [self viewControllerUsed];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
self.index++;
if (self.index > [self.pageTexts count]-1) {
self.index = 0;
}
return [self viewControllerUsed];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTexts count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
I suppose that there is an error in index pages but I don’t know it.
Thanks
I think your problem is that you are creating class level properties for view controllers. And that too you are initialising them in viewDidLoad
self.viewControllerPageContentOne = [[ViewControllerPageContentOne alloc] init];
self.viewControllerPageContentTwo = [[ViewControllerPageContentTwo alloc] init];
self.viewControllerPageContentThree = [[ViewControllerPageContentThree alloc] init];
My advise is to create view controllers and save them in an array like this:
UIViewController *page0 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentOne"];
UIViewController *page1 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[1];
UIViewController *page2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[2];
UIViewController *page3 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[3];
UIViewController *page4 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentThree"];
[self.viewControllers addObject:page0];
[self.viewControllers addObject:page1];
[self.viewControllers addObject:page2];
[self.viewControllers addObject:page3];
[self.viewControllers addObject:page4];
And then in your viewControllerUsed simply return viewControllers from self.viewControllers like self.viewControllers[self.index].
I want to reset zoom factor applied to imageView/scrollView before calling viewControllerAfterViewController.
I have an UIPageViewController "SecondViewController" and another UIViewController "ImageViewController". To explain hierarchy I prefer show some code :
#import "ImageViewController.h"
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
#synthesize pageViewController;
#synthesize imgModelArray;
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return imgModelArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[self view] setBackgroundColor:[UIColor colorWithRed: 40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0]];
// Init model and pageViewController
self.imgModelArray = [NSMutableArray arrayWithObjects:
[[ImageModel alloc] initWith:#"piaggo.jpg":#"softCat"],
[[ImageModel alloc] initWith:#"crumble.jpg":#"funnyDog"],
[[ImageModel alloc] initWith:#"piaggo.jpg":#"sleepingCat"],
[[ImageModel alloc] initWith:#"crumble.jpg":#"goodDog"],
[[ImageModel alloc] initWith:#"piaggo.jpg":#"softCat"],
[[ImageModel alloc] initWith:#"crumble.jpg":#"funnyDog"],
[[ImageModel alloc] initWith:#"piaggo.jpg":#"sleepingCat"],
[[ImageModel alloc] initWith:#"crumble.jpg":#"goodDog"], nil];
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:50.0f] forKey:UIPageViewControllerOptionInterPageSpacingKey]];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
// Init ImageViewController - Load Model - Create page 1
ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.model = [imgModelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:imageViewController];
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:pageViewController];
[self.view addSubview:pageViewController.view];
[pageViewController didMoveToParentViewController:self];
self.view.gestureRecognizers = pageViewController.gestureRecognizers;
}
// Return an ImageViewController with previous data model
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)vcFrom
{
ImageViewController *imgVc = (ImageViewController *)vcFrom;
NSUInteger currentIndex = [imgModelArray indexOfObject:[imgVc model]];
if (currentIndex == 0)
{
return nil;
}
ImageViewController *previousImgViewController = [[ImageViewController alloc] init];
previousImgViewController.model = [imgModelArray objectAtIndex:currentIndex - 1];
return previousImgViewController;
}
// Return an ImageViewController with next data model
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)vcFrom
{
ImageViewController *imgVc = (ImageViewController *)vcFrom;
[imgVc zoomX1];
NSUInteger currentIndex = [imgModelArray indexOfObject:[imgVc model]];
if (currentIndex == imgModelArray.count - 1)
{
return nil;
}
ImageViewController *nextImgViewController = [[ImageViewController alloc] init];
nextImgViewController.model = [imgModelArray objectAtIndex:currentIndex + 1];
return nextImgViewController;
}
#end
I want to call zoomX1 method (localized in ImageViewController.m), just before this one : "viewControllerAfterViewController"
What kind of event could do this ?
zoomX1 work well excepted when I am using viewControllerAfterViewController.
When I call zoomx1 inside "viewControllerAfterViewController", my view is disappearing...
But the values for height and width are not 0. Help me please !
In ImageViewController.m : zoomX1
- (void)zoomX1{
// Figure out the rect we want to zoom to, then zoom to X1
UIImage *currentImage = [UIImage imageNamed:model.imageName];
CGSize currentImgSize = currentImage.size;
CGFloat w = currentImgSize.width;
CGFloat h = currentImgSize.height;
CGFloat x = 0;
CGFloat y = 0;
CGRect rectToZoomTo = CGRectMake(x, y, w, h);
[self.scrollView zoomToRect:rectToZoomTo animated:YES];
}
EDITED (2X) :
I think I have a problem with UIPanGestureRecognizer.
In "SecondViewController.view" and "pageViewController" : PanGesture is used to move to next/previous "ImageViewController" with "viewControllerAfterViewController" and "viewControlleBeforeViewController"
In "ImageViewController.scrollView" : PanGesture is used to move to a specific area when I zoomed on an image.
I didn't add programmatically a PanGesture. I just want to keep the panGesture inside scrollView which is reponsible of moving inside an Image. And keep the other panGesture linked at view level which is responsible of switching page. I think they are private Apple's method.
But when I pan inside scrollView there is a problem.
I had a similar problem in one of my projects and what I did I added an extra target to the UISwipeGestureRecognizer of the UIPageViewController. You can try this (it may be a considered by other developers a hack but I don't think so).
In viewDidLoad or other init/setup methods you can try something like this:
for(UIGestureRecognizer *gesture in yourPageViewController.gestureRecognizers) {
if([gesture isKindOfClass:[UISwipeGestureRecognizer class]]) {
[gesture addTarget:self action:#selector(zoomX1)]
}
}