In my project, I'm using the storyboard with 2 tabs. What I want to create is in the first tab, when you swipe left, another layout with text will show and when you swipe left again, another layout shows with other information (so lets say I want 10 different layout templates but I need to be able to change the text from the layout templates.
So this is my storyboard:
And in the "First View" I need to be able to swipe left and show a layout with text, swipe left again and show (for example) the same layout with another text, swipe left again show another layout with text and so on. So in total there are 10 layout templates where I need to be able to change the text in code.
So basically what I'm aiming for is the same as the start window on the iPhone/iPad where you can swipe between the screens where the app icons are on. How can I accomplish this with the same animation?
What you are looking for is called UIPageControl. The class reference can be found here and a really good tutorial can be found here.
If you want a more fancy UIPageControl with more customizable options I suggest you try out any of these. (The SMPageControl is one of my own personal favorites)
EDIT due to comments:
Here is a link to the project from the tutorial above.
In CustomPagerViewController he calls
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"View1"]];
which gives the equivalent result as
UIViewController *aViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"View1"];
[self addChildViewController:aViewController];
Now, if you want to add several ViewControllers you could do a loop as follows
for(int i = 0; i<yourNumberOfViewControllers; i++) {
YourViewControllerClass *aViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"YourIdentifier"];
[aViewController setSomeProperty:someValue];
[self addChildViewController:aViewController];
}
Hope it helps!
Related
I have a program with one main view controller, which includes a button that the user can tap to display 4 pages of "Quick Help" via a UIPageViewController. The 4 pages are QuickHelpViewController0ID - QuickHelpViewController3ID, and each is a standard UIViewController. When they tap the button, I run this:
-(void)showQuickHelp
{
// Load the quick help page view controller
self.quickHelpPageVC = [self.storyboard instantiateViewControllerWithIdentifier:#"QuickHelpPageViewControllerID"];
self.quickHelpPageVC.dataSource = self;
// Create initial quick help page
UIViewController *quickHelpVCA = [self quickHelpVCForPageIndex:0];
NSArray <UIViewController *> *quickHelpVCs = #[quickHelpVCA];
// And assign it to the page VC
[self.quickHelpPageVC setViewControllers:quickHelpVCs direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self presentViewController:_quickHelpPageVC animated:YES completion:nil];
} // showQuickHelp:
I also provide a UIPageViewControllerDataSource to create each of the 4 pages as needed when the user scrolls to the next/previous page.
This works fine on iOS 9.3 and 10.x. It also works on 11.0 for all devices except the iPhone X (simulator). On that, the row of 4 page indicator dots is way down at the bottom of the screen, only 1 or 2 pixels above the new "home bar" that iOS 11 provides (slide up to switch apps, etc).
I found a video from Apple called Building Apps for iPhone X where the developer discusses fixing a similar problem, but in that case his solution was to simply change auto-layout to constrain a child UIPageControl to the bottom "safe area" instead of the traditional bottom layout guide. But I'm not using a UIPageControl on another view controller; I'm using a UIPageViewController, and I don't see any way to control the location of the page controls along the bottom of the window. (Yes, I've enabled the "Use Safe Area Layout Guides" option in Interface Builder.)
I can't imagine that iOS 11 sizes the UIPageViewController incorrectly by default in my scenario, nor do I see any obvious way to fix it. Any suggestions?
The fix for this is coming in 11.2
https://9to5mac.com/2017/10/30/ios-11-2-beta-1/
UIKit -
Resolved Issues
Displaying a page control in UIPageViewController on an iPhone X no longer overlaps the home indicator at the bottom of the screen. (34478195)
I had the same issue, but found that if I uncheck the 'Extend Edges - Under Bottom Bars' on the main view controller, the dots move up and appear correctly for iPhone X on the simulator. Unfortunately it also moves the dots up on all other devices... might not be an issue if there isn't too much on the page, but for me it truncated one page with lots of text on it.
It definitely looks like a bug, so I'll wait for Apple to hopefully fix the issue, as I'd rather not put nasty hacks to programmatically change the extend edges under bottom bars flag just for iPhone X
I want to add a second view controller to my project with a swipe navigation. Which is the easiest way?
As you can see in the picture I have these buttons in the first view, I want to add more. I also have a background picture which is not in the picture
(below), is it possible to keep it for both views? So when I swipe to the right the background should't move, only the buttons.
Also could you please explain to me how I should make it step by step, because I am new into coding and have almost no experience.
I think what you are trying to find is paging using UIScrollView. Check out this link.
Hope this helps you.
you can use the custom class called ADPageControl. Here is the reference link : https://www.cocoacontrols.com/controls/adcustompagecontrol.
And for that image you can set the common image below your container view. Please go through the link and try to implement it.
Basically you need a UIPageViewController But you have tweak a little bit. You can find a tutorial about that here
Few Points
Create PageViewController with buttons
Make each Page views background color as clear color so your background image will be shown all the time even when you swipe.
Please don't expect full code from SO
I think you trying implement something like ..look below code
its scrollview paging
// viewArray contains paging views
viewArray = [[NSMutableArray alloc] initWithObjects:self.viewOne, self.viewTwo, nil];
// adding all views as scrollview subview
for (int i = 0; i < viewArray.count; i++) {
self.scrollView.pagingEnabled = YES;
[self.scrollView addSubview:viewArray[i]];
}
// this time you need to set scrollview contentSize but in X axis ..
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * viewArray.count, self.scrollView.frame.size.height);
have a note: you can create views using storyboard or programmatically but must set the x position of views which you want to appear on swipe.. hope this helps.
I'm trying to make something like UIPageViewController where I can swipe between different VC's. But instead of custom dot control I need to have custom buttons. So that either user can select different VC with button click or can swipe.
Right now I'm using UIScrollView to make this. I don't know how to proceed with buttons so I need help with that.
Is there any custom control that'll be useful for this?
You can do it in different ways. If you have three pages, you can create a UI with three buttons(or a tab bar) and in the action you can call:
[self.pageViewController setViewControllers:#[[self viewControllerAtIndex:YourPageIndex]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES
completion:nil];
UIPageViewControllerNavigationDirectionReverse or UIPageViewControllerNavigationDirectionForward can be used as required.
This is how we do it.
Or you can use any custom libraries:
Carbon kit is a working library. Here you can find many of them.
OR TRY THIS( a simpler example on carbon kit )
I am currently developing an app that contains a music player. As of now it has a play, pause, & a select song button that shows the current song playing. Right now, the player is always on the screen. I want to make it so theres a button in the middle of the page so that when users click that, the whole media player with the play, pause, and select song button/icon will appear. When they click on that middle button again it shall hide those icons.
If anybody could point me in the right direction whether it be tutorials already out, or other discussions (I could not find any ones really) that would be awesome!
NOTE: I'm not trying to make the popover menu that facebook uses. This menu/audio player will expand/retract horizontally over the current view
Thank you in advance!!!!
Sounds like you need to look into the .hidden property of view objects (allows you to make views visible/not-visible), and possibly the ability to move views around on the screen with the .frame property (setting location, height/width).
Without some more detailed information about the effect you're trying to achieve, it's difficult to say more than that. If you use interface builder to set up the view/UI-objects you want to display, you can simply set the base view to hidden in interface builder and then when the user clicks your button set .hidden=NO for that view.
Note: to be able to show/hide everything as a unit like this, I'm assuming that you use a single UIView object in interface builder as the container (sized and placed where you want it) and then add your controller buttons as sub-objects inside that single view. This allows you to show/hide everything by just setting .hidden property for the containing view.
I'm not exactly sure what visual effect your looking for, but I think you already said it - just hide them.
You can do that a couple of ways.
One simple way is just to put those elements inside of their own view. Use a storyboard or xib file. Put your buttons and controls you want to hide show in a view.
Then create a reference in your view controller to that view. call it controlsView.
#property (strong,nonatomic) IBOutlet UIView *controlsView;
Make sure you connect that view.
Then when the button is pushed, just hide that entire view:
self.controlsView.hidden = YES;
When pushed again, show it:
self.controlsView.hidden = NO;
If you want a bit smoother look and feel, wrap it in an animation like this:
//to hide
[UIView animateWithDuration:2 animations:^{
[self.controlsView setAlpha:0];
} completion {
self.controlsView.hidden = YES;
}];
//to show
self.controlsView.alpha = 0;
self.controlsView.hidden = NO;
[UIView animateWithDuration:2 animations:^{
[self.controlsView setAlpha:1.0];
} completion {
}];
hope that helps
Note: Using Monotouch and doing all the UI Programatically.
Hello everybody,
I have a question.
I have this main UIViewController object, and I have 2 UIVIews inside it. This views will perform commands in some devices, etc. I'm planning to do some menu with a slider effect appearing from the left side as it's drawn below. In this menu the user will select some buttons, and this is gonna make to change the another two UIViews.
Here's my question:
I'm planning to use Modal View Controller as UIModalPresentationPageSheet, but how can It appear at the center of the screen horizontaly. I'd like to put it on the center on the left side. How can I change it?
If it's impossible, should I use the UIPopover?
Image Below
Thank you.
Lyniker
I don't think either will get you the animation effect you want. In general I would choose to slide in a view using UIView animation:
if(IsDrawerVisible == false) {
UIView.Animate(0.5, () => {
DrawerView.Frame = new RectangleF(
this.View.Bounds.Left + 300,
DrawerView.Frame.Y,
DrawerView.Frame.Width,
DrawerView.Frame.Height);
}, UIViewAnimationOptions.CurveEaseIn);
}
else {
// Move the frame of the DrawerView by subtracting from Frame.X
}
Of course you need a reference point (usually the parent UIView's left bounds) and do the appropriate calculations to move the "Drawer" component into view. This can be arbitrary though :-)
NOTE: If DrawerView is of type UIViewController / DialogViewController please use the new iOS 5 custom containment APIs or you'll get some seriously wonky behavior. See my blog post on child view controllers here:
http://blog.devnos.com/wont-somebody-please-think-of-the-children