UIPageViewController with a last view without page indicator - ios

I would like to have 4 views that the user can swipe left or right.
For this I am planning to use UIPageViewController.
What is special is that the last view should not have the page indicator at all. I would like to swipe it away with the view that is before the last one. Is this possible with UIPageViewController?
Here is a picture of a swipe moving to the last view:

I think that's impossible to achieve what you say with UIPageViewController. Because you can't get the value how far the current view is moved by now.
To get that value you can custom a UIScrollView and animate the page indicator yourself in the delegate method - scrollViewDidScroll:

There's no built-in support for conditionally showing the page control, depending on what page you're on.
If you could get the UIPageViewController to query its UIPageViewControllerDataSource, you could try returning 0 from presentationCountForPageViewController: while transitioning to the last view controller, but it will never be a good solution, as you're trying to circumvent what the controller is internally managing for you.
You can use UIAppearance to change the color of UIPageControl.
This can be used to only apply a style for a particular view controller, as follows:
UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[LastViewController class], nil];
pageControl.pageIndicatorTintColor = [UIColor clearColor];
pageControl.currentPageIndicatorTintColor = [UIColor clearColor];
pageControl.backgroundColor = [UIColor clearColor];
This, however, won't remove it from the view, and the page control's gestures would still be active.

Related

PageControl backgroundColor when used in UIPageViewController

I'm trying to implement a simple tutorial using UIPageViewController in iOS7. I implement all methods in UIPageViewControllerDataSource and it gives me a UIPageControl. Everything works except that the pageControl's background is not transparent so it blocks part of the other views behind it.
I try to change the pageControl's appearance with the following code
pageControl.backgroundColor = [UIColor greenColor]; //works, background is green
pageControl.backgroundColor = [UIColor clearColor]; //not working, background is black.
//updates
It turns out that the black color is the background color of the PageControl's layer. And this Page Control layer is not on top of my own ViewControllers that I used for pages. They are in parallel.So no matter how I modify its colors, I cannot get my ViewControllers to take the full screen.
Is there an easy way to move the PageControl on top of my ViewControllers?
It could be the background of the parent view. I had a similar situation where the background color was actually the background of my parent control, not my own. Here is a tool I use that helped me narrow this down : http://www.sparkinspector.com. Here is another tool that does the same thing : http://revealapp.com.
Also one more thing - not sure if this would apply to your case, but it could be the background layer that might need its color set
CALayer *layer = self.layer;
[layer setBackgroundColor:[UIColor clearColor]];
if you set something to be clear color, the background color then depends on whatever is on the background, the view the page control is in (usually a uipagecontrol) has no background, and this is why you're seeing it as black.

Presenting a semi-transparent UITableView from a UIViewController

I'm working on an app that will rely on one main view controller with a row of buttons at the bottom to display other views with information. From one of these buttons I want to present a tableview that presents a list of song titles. This app plays sound files, and I want the user to be able to tap a button, then select a song to be the default song to play. I want to present this tableview with a uiview animation, and I want it to be semi-transparent and only fill a portion of the screen. I've tried creating a UITableViewController and then presenting it from the main view controller like so:
UITableViewController *tableView = [[UITableViewController alloc]init];
[self presentViewController:tableView animated:YES completion:nil];
This presents a view controller that fills the entire screen though, which is not what I want. And changing the view controller's frame at instantiation time doesn't seem to have an effect. I can just animate a UITableView into the main view controller's view, but then I'm not so sure who is supposed to be the delegate and data source. Any suggestions? Thanks in advance.
While adding table view as a subview, u can set its frame size or bound, and display it with animation whatever you like. Yes, you can set delegate and datasource to self while adding .
I use: (in viewDidLoad)
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
Then in cellForRowAtIndexPath:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];
Not sure if this is what you wanted, but it gives you the option to make everything clear. (obviously the alpha would change for your case, but that measures the opacity of the cells)

Custom UINavigationBar animation

I've subclassed UINavigationBar in order to set a custom background image.
I'm using it to initialize a UINavigationController with:
-(id)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass
The problem is that when new UIViewControllers get pushed on to the NavigationController stack, the title text animates in from the right across the background image in a way that looks a bit sucky.
Problem: How to tweak the animation so e.g. it fades in as it animates across.
The closest I've come is by creating a custom fade-up animation in the pushed/popped ViewController class. I use a NSTimer to trigger changes to the alpha of the titleView:
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
...
-(void)setAlpha:(float)alpha
{
titleView.textColor = [UIColor colorWithRed:grayShade green:grayShade blue:grayShade alpha:alpha];
}
However, if I trigger this in 'ViewDidAppear' it's already too late and the fade-up starts after the new view has finished sliding in. I figured that I could trigger it in 'ViewWillAppear' but that this might lead to indeterminate and inconsistent timings on different devices. Am I right in this assumption and if so, how can I customize the animation in the way I want to?

Pattern to fill the entire screen

Every screen of my app has a common tint. Its not a background. Its a pattern that fills the entire screen and it is top of all the views. You can see the pattern flow continuously from one view to another inside the same screen. And it neither obscures other elements nor participate in event handling.
I tried implementing it with this code in my ViewController.
UIColor* texture = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Texture.png"]];
UIView* tintView = [[UIView alloc] initWithFrame:self.view.bounds];
[tintView setBackgroundColor:texture];
[tintView setAlpha:0.5];
[self.view addSubview:tintView];
But it doesn't pass on touches to the views behind it.
tintView shouldn't participate in any event handling. Rather it should let other elements behind it, handle the events like they do it normally.
Other way of doing it is set this as a background of the view property of a UIViewController and set a common alpha for all other subviews of view to show the pattern behind. That will be redundant in most ways.
Any better way of doing this?
Make your tintView a subclass of UIView and implement the hitTest:withEvent: method, returning nil. This will make your view transparent to touches. Or set userInteractionEnabled to NO.
Set the background color with a Textured image
UIImage *bgimg = [UIImage imageNamed:#"Texture.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:bgimg];

UIPageController in conjuction with UIPageControl?

I have been using UIPageController to navigate between different controllers. Now I would like to add that dots at the bottom, so user can see on which controller he is at. That is achieved via UIPageControl. Is there easy way to combine those two?
From the bottom of UIPageViewController.h (iOS6+) ~
A page indicator will be visible if both methods are implemented, transition style is 'UIPageViewControllerTransitionStyleScroll', and navigation orientation is 'UIPageViewControllerNavigationOrientationHorizontal'.
Both methods are called in response to a 'setViewControllers:...' call, but the presentation index is updated automatically in the case of gesture-driven navigation.
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); // The number of items reflected in the page indicator.
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(6_0); // The selected item reflected in the page indicator.
Otherwise, I think you need to add a UIPageControl to your UIPageViewController and basically tie them together to keep them in sync...but then you do have to do all the tying manually.
If you are using Page Based application template of Xcode then go to
Attribute inspector and set Transiton style property to Scroll.
and go to your application AppDelegate.m file and set the tint color for the
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
For the page based Xcode template its already their for iOS 6,iOS 7 just its color is set to white.

Resources