UIPage Control Buttons - ios

Right now I'm using page control to display 5 images. However the circle indicators showing which page you are on are appearing at the bottom of the view instead of right underneath the image like I want. I attempted to change the location using "pageControl.frame = CGRectMake(110,5,100,100);" but it does nothing.. Any reason why this is not working?
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a
nib.
_pageData = #[#"slide0.png", #"slide1.png", #"slide2.png",
#"slide3.png", #"slide4.png", #"slide5.png"];
_pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:
UIPageViewControllerNavigationOrientationHorizontal
options:nil];
_pageViewController.delegate = self;
_pageViewController.dataSource = self;
DataViewController *startingViewController = [self viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = #[startingViewController];
[_pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
_pageViewController.view.frame = pageViewRect;
[_pageViewController didMoveToParentViewController:self];
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.frame = CGRectMake(110,5,100,100);
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
}

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed {
pageControl.currentPage = pageViewController.currentPageNumber;
}

Related

UIPageViewController VCs overlapping

I'm facing a strange problem whereas the UIViewControllers I present in a UIPageViewController have a width of 328 instead of 320 and appears to be flowing out of their bounds.
When viewing say page index 0, I can see a mm or two of page index 1 on the right hand side. Why is this? I'm using AutoLayout and create my UIPageViewController like so:
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:#{UIPageViewControllerOptionInterPageSpacingKey : [NSNumber numberWithFloat:pageSpacing]}];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
[self.pageViewController willMoveToParentViewController:self];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
/* remove dots */
NSArray *subviews = self.pageViewController.view.subviews;
UIPageControl *bottomControl = nil;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
bottomControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
bottomControl.hidden = true;
/* set viewcontrollers */
self.navViewControllers = #[
leftViewController,
centerViewController,
rightViewController
];
[self.pageViewController setViewControllers:#[self.navViewControllers[1]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

Unhiding the navigation bar after popping a UIPageViewController

I am having trouble trying to unhide the navigation bar in my app. I have a UIPageViewController created in a UIViewController like so:
//Hide the bar
self.navigationController.navigationBar.hidden=YES;
// Create page view controller
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:229/255.0 green:145/255.0 blue:217/255.0 alpha:1];
pageControl.backgroundColor = [UIColor whiteColor];
//Call our helper method
StickerContentViewController *startingViewController = [self viewControllerAtIndex:0];
//Need to pass the first one, don't put them all in here
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//setup
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
When I pop the UIViewController (the one containing the UIPageViewController) using [self.navigationController popViewControllerAnimated:YES]; I can't get the navigation bar to unhide for the previous screen. I have tried placing self.navigationController.navigationBarHidden=NO; in the viewWillDisappear, viewDidDissappear. I also tried putting it in the content view controller but still no luck. Could someone give me a pointer to what I might be doing wrong here please?
Fixed it, just posting in case someone else has an issue. I was using self.navigationController.navigationBar.hidden=YES; when I should have used self.navigationController.navigationBarHidden=YES;. Not sure what the difference is. Anyway I hide the bar in the viewDidLoad and unhide it in the viewWillDisappear and it works now. thanks guys

iOS How can I set transparent in Container viewcontroller

I had embed UIPageViewController in the Root Viewcontroller.
Like below photo .
But I want to set First,second View controller background transparent, and it's still can show view controller text 1 and 2.
So It will show Root background color(black) and the root view controller can swipe though the uipageviewcontroller.
My pageviewcontroller part code below:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro2ID"];
myViewControllers = #[p1,p2];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
Have anyone can teach me how to set the containerview background color transparent and can show 1 , 2 text?
(It is sample code, so that just 1, 2 text)
thank you very much.
This should do the trick:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
The issue is that the background view of your UIViewController was not transparent.

Issue with iOS7 and UIPageViewController

I have a UIPageViewController that is added as subview on UIView. The UIView sits on the top of UIViewController's view, at start it puts the UIPageViewController lower than it should sit, but right after I click on the next button to push the next UIPageViewController's view, it send it back to the correct position.
What is he doing that? I tried everything but still can figure out the problem.
This is how it looks:
What seems to be the problem? Thanks in advance!
EDIT: This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
DataChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageController.dataSource = self;
self.pageController.delegate = self;
self.pageController.view.userInteractionEnabled = NO;
self.pageController.view.frame = self.view.bounds;
[self.pageControllerParent addSubview:self.pageController.view];
[self addChildViewController:self.pageController];
self.currentPageControllerIndex = 1;
}
- (IBAction)buttonNextDidClicked
{
self.buttonNext.enabled = NO;
__weak typeof(self) __self = self;
[self.pageController setViewControllers:#[[self viewControllerAtIndex:self.currentPageControllerIndex]]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:^(BOOL finished) {
__self.currentPageControllerIndex++;
__self.buttonNext.enabled = YES;
}];
}
#pragma mark - UIPageViewControllerDelegate & DataSource
- (DataChildViewController *)viewControllerAtIndex:(NSUInteger)index
{
DataChildViewController *childViewController = [[DataChildViewController alloc] initWithNibName:#"DataChildViewController" bundle:nil];
childViewController.index = index;
return childViewController;
}
So, I've figured out the problem.
On viewDidLoad I had this line:
self.pageController.view.frame = self.view.bounds;
When it actually should be:
self.pageController.view.frame = self.pageControllerParent.bounds;

Setting up Page Curl animation with UIPageViewController

I am new to iOS and I am using UIPageViewController. Here is my code:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
firstVC *first1 = [[firstVC alloc] initWithNibName:#"firstVC" bundle:nil]; return first1;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
secondVC *second1 = [[secondVC alloc] initWithNibName:#"secondVC" bundle:nil]; return second1;
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed { NSArray *viewControllers = nil; viewControllers = [NSArray arrayWithObjects:first,second, nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:NO completion:NULL];
}
-(UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation {
NSArray *viewControllers = nil; viewControllers = [NSArray arrayWithObjects:second, first, nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:YES completion:NULL]; return UIPageViewControllerSpineLocationMid;
}
- (void)viewDidLoad { [super viewDidLoad]; [self.navigationController setNavigationBarHidden:NO]; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.title = #"DEMO"; NSDictionary *options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey]; self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerSpineLocationMid options:options]; self.pageViewController.delegate = self; self.pageViewController.dataSource = self; first = [[firstVC alloc] initWithNibName:#"firstVC" bundle:nil]; second = [[secondVC alloc] initWithNibName:#"secondVC" bundle:nil]; NSArray *viewControllers = [NSArray arrayWithObjects:first,second,nil]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerSpineLocationMid animated:NO completion:nil]; [self addChildViewController:self.pageViewController]; [self.view addSubview:self.pageViewController.view]; self.modalPresentationStyle=UIModalPresentationCurrentContext; [self.pageViewController didMoveToParentViewController:self]; CGRect pageViewRect = self.view.bounds; pageViewRect = CGRectInset(pageViewRect, 20.0, 20.0); self.pageViewController.view.frame = pageViewRect; self.view.gestureRecognizers = self.pageViewController.gestureRecognizers; self.pageViewController.doubleSided=YES; }
It is loading double sided pages in both orientations but a problem arises when I swipe the page and only one view is shown. I want a page-like animation. Please help. Thanks in advance for help and support.
where do you initialize your UIPageViewController?
at the point of initializing you MUST define the transition style as it's a readonly property.
The code should look like this;
self.pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];

Resources