I wanna create an app that will have three view controllers. To navigate between them I wanna use swipes and page control (UIPageControl). Also i wanna do this using Stroryboards as much as possible.
What's the best way to implement this?
Thanks
This could also be achieved using the storyboard and segues.
The basic idea is you would create the segues between the 3 UIViewControllers, then capture the swipe gestures, and then call the perform segue to move between views.
On each view, you will have one or two segues:
[ View 1 ] -> gotoView2
gotoView1 <- [ View 2 ] -> gotoView3
gotoView2 <- [ View 3 ]
Here is a video of how to do it.
http://www.youtube.com/watch?v=5u1-DGiUhXU
This is actually quite simple to implement if you know what you need to do. UIPageControl does not help you to achieve paging, it merely displays the dots like on springboard to show what page you are on.
As far as I am aware storyboards let you switch between views or controllers, which if a paging effect is what you are after is not going one much use to you. Your best bet would be to use one view controller and a scrollview on its view.
If you set
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
Or something to that effect (you can change the content size to whatever size you want your pages to be. Your scroll view will then snap to those boundaries when scrolling.
If you want to display the current page with a UIPageControl you will need to also add one to your view controller's view. Then implement the UIScollViewDelegate protocol and the method:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControl.currentPage = (calculate current page here);
}
In order to make you pages, simply add subviews to the scroll view and it will page between them depending on your set content size.
Hope this help, if it seems unclear or you need any more help, let me know :)
Related
Apologies if this has been asked before. I can't find any reference to this particular problem though.
I have an app which is basically a table view nested within a navigation controller. Each item from the table segues to a fresh view (via a generic push transition), containing some content within a scrollview. I have set this all up using storyboard for ease of layout.
When you click an item in the table, the intention is for the table to slide off the screen to the left and be replaced by the content view. This works fine in iOS 6, but since testing the app on iOS 7 I've noticed the functionality is different.
In iOS 7 the content view slides into frame as normal, but the table view only slides a little way to the left - still visible behind my new content. It disappears very suddenly after half a second or so, but the effect is very jarring as it creates a momentary overlap of two views.
This is only a problem because my content views have transparent backgrounds, but this is important to maintain for the effect I want. So just to be clear, my content view slides in over the top of the menu, which subsequently disappears. Looks very odd.
Any help on this would be much appreciated. I'd be curious to know the reason for this change and if there's a way I can fix it. Preferably by making the menu slide all the way offscreen again.
Thanks!
I had the same problem.
Try to add into target ViewController (that shows up after push)
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor redColor];
}
If all is ok you can change background to something like that
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"GreenBkg.png"]];
ps. tableView needs to be defined as #property in your .h filw
I want to show a logo UIView always on top when the app running,
I know there is a way to do that,add same UIView to every UIViewController,
but I think this is not the best way to do that.
when i have lot of pages,and modify the logo UIView,must modify it every page.
Did someone have better way to do this?
thanks.
look like this:
Since you only every have one window per app, and view's don't have levels, you have to make sure that view stays on top of the hierarchy, no matter what. One relatively easy way is to add it directly to the window above the rest of the interface (the navigation controller):
In applicationDidLaunch:
// After the main navigation controller or tab controller has been added
// either programmatically or in the xib:
UIImage *logo = [UIImage imageNamed:#"logo.png"];
UIImageView *logoView = [[UIImageView alloc] initWithImage:logo];
[self.window addSubview:logoView];
Actually, I think that (a) creating a subclass of UIView that shows your logo and has all the necessary setup in it and then (b) adding this subclass to each view controller is the cleanest and most manageable way to do this.
The reason I prefer this method over adding the view to the window is because if you ever have a view that you don't want to show the logo, you won't need to show and hide something you added to the window. Also, adding directly to the window may cause rotation challenges on certain iOS devices in my experience, depending on what you're doing.
Also, to make sure your logo view is always on top of the view hierarchy, you can do two things:
If the view already exists, you can bring it to front using [UIView bringSubviewToFront:]
[myParentView bringSubviewToFront:myLogoSubview];
If you are creating the view, it will be on top when you add it with [UIView addSubview:]
// Set up myLogoSubview first here with alloc+init, etc.
[myParentView addSubview:myLogoSubview];`
It looks like in your image you would replace myParentView with self.view and myLogoSubview with the view you're looking to keep on top, but this is just my assumption based on your image.
I'm trying to create an app with UITabBarController, in order to use Cocoa's own memory and view controllers management for switching between different view controllers.
However I do need to make a very custom UITabBar, which after much Googling I found out is not possible. Several things are not possible with original UITabBar:
changing position and size of the TabBar,
adding custom (non-tab) elements to the toolbar, such as search/dropdown
Is there any "legal" method of completely changing the design/subviews of TabBar but in the same time making use of UITabBarController and still getting app approved by Apple?
Thank you for your help.
About changing the size you can extend UITabBar and overwrite the function sizeThatFits.
I'm sorry for not having an answer for the other points.
- (CGSize)sizeThatFits:(CGSize)size {
CGSize auxSize = size;
auxSize.height = 54; // Put here the new height you want
return auxSize;
}
I will tell you as soon as I will discover it.
Not much can be customized in tabbar but there are some good examples :-
Custom Tabbar by iDevRecipes
Custom TabBar by brianCollins
It might not be exactly what you need but will give you direction.
I'm working in Xcode 4.2 and am developing an app where I want the menu screen to use a Split View. Really, all I need the Split View Controller for is to split some of the menu options into a left pane and right pane. I want to be able to set custom sizes for the master and detail view controllers, but nothing seems to be working for me. I've tried updating the frame sizes for each view controller with code like:
[self.view setFrame:CGRectMake(0, 0, 768, 502)];
in the viewDidLoad functions, but that doesn't seem to affect anything.
Is there a way to set custom sizes for the master and detail view controllers of a split view controller without instantiating the view controllers in say the AppDelegate.m file? I want to be able to edit each of the view controllers in the storyboard as they are menu screens with a lot of buttons and such.
Edit:
In iOS 8+, the relative widths can be changed by specifying the minimum/maximumPrimaryColumnWidth properties or the preferredPrimaryColumnFraction.
The below answer is still true for iOS < 8:
You can't change the sizes for a split view controller.
See here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
"The UISplitViewController class is a container view controller that manages two panes of information. The first pane has a fixed width of 320 points and a height that matches the visible window height. The second pane fills the remaining space."
Use MGSplitViewController. It offers similar API to UIViewController, but offering additional features, such as split position, which is what you need.
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
return proposedMinimumPosition + 238;
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
return proposedMaximumPosition - 200;
}
before the above delegate method add [splitView addDelegate:self];
I'm working on an an app that updates both a UITableView and a UIScrollView. I like how UITableView updating works. As I add, remove, or update items, I call insertRowsAtIndexPaths:withRowAnimation:, reloadRowsAtIndexPaths:withRowAnimation:, and deleteRowsAtIndexPaths:withRowAnimation: as appropriate. However, updating the UIScrollView has turned out to be more of a challenge.
So how can I do it? My UIScrollView contains images, and I want to be able to insert, update, and remove individual images -- with animation -- efficiently and smoothly, and perhaps in random order. How does one do this sort of thing?
As an example, I have code like this in my UIScrollViewDelegate implementation for adding a new image:
if (newImageindex == currentImageIndex) {
[scrollView setNeedsDisplay];
[scrollView setContentOffset:portalView.contentOffset animated:YES];
} else if (newImageIndex < currentImageIndex) {
currentImageIndex++;
CGPoint offset = portalView.contentOffset;
offset.x += portalView.frame.size.width;
portalView.contentOffset = offset;
}
This is close, I think, but not quite right. I end up with the images added, but the UIScrollView seems to scroll to a position before the first image in the view. If I start scrolling it by hand, the first image appears. It's like it's scrolled to position -1 in my images.
The example may not help to highlight my problem much, but surely it's a common need to dynamically rejigger the images appearing in a UIScrollView. What's the state of the art on this?
A UIScrollView is not so specialized and structured as a UITableView. The former is a generic view that scrolls and zooms anything you put in it, and you can put any subviews into it anywhere, whereas the latter is made especially to display lists of cells stacked on top of each other.
So the answer is: you need to animate the subviews in the scrollview yourself. There are various libraries like Three20 which provide frameworks for creating more advanced views, you'll need to use a suitable component from one of those or roll your own.