I'm trying to present a view controller with its presentation style set to form sheet. However, when the view controller appears, it is positioned to the right of the screen, not in the center. I am not sure why this is happening, or what I should do. All of these coordinates are correct!
CGSize size = CGSizeMake(650, 550);
//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nav animated:YES];
nav.view.superview.frame = CGRectMake(0, 0, size.width, size.height);
nav.view.superview.center = self.view.center;
It seems that whenever I remove the last two lines, I get what I assume to be the behavior that you are looking for.
CGSize size = CGSizeMake(650, 550);
//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nav animated:YES];
I'm not sure exactly what you were trying to do with those two lines, but without them the view is centered.
Related
I already have the basic code for a utility application, but when the application flips to the second view I want to add a tabbarItem to the bottom of the flipped view only, if the view is flipped back to the original view the tab bar shouldn't show up. How can I add this feature, I'm using simulator 4.1 by the way, thanks!
Here's the code that shows the flipped side when the button is clicked, I want it to flip to a tab bar controller instead.
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
You can hide the UITabbar by using the following code
[yourTabBar setHidden :YES];
and show it using the following code
[yourTabBar setHidden:NO];
By Show/Setup do you mean adding the tabbar controller on the view??Well i am assuming that..You can Add the tabbar controller as a rootviewcontroller of your window i.e. your AppDelegate.Here is the sample Code:
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navCon1=[[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *navCon2=[[UINavigationController alloc] initWithRootViewController:viewController2];
UIViewController *viewController3=[[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UINavigationController *navCon3=[[UINavigationController alloc] initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navCon1, navCon2,navCon3, nil];
self.window.rootViewController = self.tabBarController;
You're switching between two UIViewControllers, right? Let the second view controller, the one that appears after flipping, be a UITabBarViewController.
(void)viewDidLoad {
[super viewDidLoad];
UINavigationController *naviController = [[UINavigationController alloc]init];
[self.view addSubview:naviController.view];
}
If I add navigation controller in the view, it appears about 20 pixels below status bar. I want it appears just below status bar. How do I fix this?
Just set the frame for naviController.view
naviController.view.frame = self.view.frame;
Assuming that you're adding your navigation bar at 0,0 then it looks like you're view isn't positioning correctly.
The easy fix is to move your bar to be at 0,-20
UINavigationController *naviController = [[UINavigationController alloc]init];
CGRect frame = [naviController frame];
frame.origin.y = -20;
[naviController setFrame:frame];
[self.view addSubview:naviController.view];
However, that's a hack.
Try something like this instead :
[[self view] setAutoresizesSubviews:YES];
UINavigationController *naviController = [[UINavigationController alloc]init];
[naviController setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin];
[self.view addSubview:naviController.view];
That might work?
DeclareUINavigationController in the app delegate's applicationDidFinishLaunching:
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:viewControllerOfYourExample animated:YES];
I want to show the subview of a view in popover.
To elaborate,
I have a mainViewController.
I hava a subview 'songListView' in this mainViewController.
I have a button titled 'list' in the mainViewController' itself.
I want to show the songListView in popover on clicking the button 'list'.
So, how should I do this.
You could use the below code as a reference for showing PopOver from a UIButton
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
My problem is solved.
I just created another View Controller class, i.e. 'TempPopoverView'.
Then I set the view of this TempPopoverView equal to the subview of my MainView
Here is the code snippet from my code:
TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:#"TempPopoverView" bundle:nil];
[self. songListView setHidden:NO];//songListView is subview of MainView
viewController.view=self. songListView;
UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];
[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
[navCont release];
U can use presentModalViewController on your main view.
For example
SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];
There are different animations possible as well.
as simple as you think to add subview in self.view
[popoverController.contentViewController.view addSubview:yourselfobject];
A view is presented modally:
[self presentModalViewController:modalNavController animated:YES];
This view uses a UITabBarController with 4 elements. One of these elements, "Info" has a button that's only visible if its available. If the button is clicked, it needs to push to another view controller, but I'd also like to maintain the tab bar from it's parent view. I haven't been able to figure out how to do this with or without keeping the tab bar. Ive tried pushing and presentingModally in all the places that I could image. How should this be done properly?
Creating tab bar:
infoController.title = #"Info";
streetViewController.title = #"Street View";
reviewController.title = #"Reviews";
streetViewController.tabBarItem.image = [UIImage imageNamed:#"flag.png"];
infoController.tabBarItem.image = [UIImage imageNamed:#"openMarker.png"];
reviewController.tabBarItem.image = [UIImage imageNamed:#"reviews.png"];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
infoNC.navigationBarHidden = YES;
[tabBarController setViewControllers:
[NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];
[self.view addSubview:tabBarController.view];
When you add the view controllers to the tab bar controller you need to do this:
MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];
then add nc1 instead of your custom view.
Then in MyCustomViewController to push another view controller do:
[self.navigationController pushViewController:(UIViewController *)page animated:YES];
That should work for you, and keep the tab bar controller.
Right, this may not be possible but maybe it it...
I have 3 UIViewControllers, each with their own XIB files which contain the layout for each slide of a presentation (each slide will contain video, images, other interactive elements). I have hooked them all up to a UIScrollView by adding them one by one, see below:
page1 *vc = [[page1 alloc] initWithNibName:#"page1" bundle:nil];
vc.view.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);
[sv addSubview:vc.view];
[vc release];
page2 *vc2 = [[page2 alloc] initWithNibName:#"page2" bundle:nil];
vc.view.frame = CGRectMake(1024.0f, 0.0f, 1024.0f, 768.0f);
[sv addSubview:vc2.view];
[vc2 release];
page3 *vc3 = [[page3 alloc] initWithNibName:#"page3" bundle:nil];
vc.view.frame = CGRectMake(2 * 1024.0f, 0.0f, 1024.0f, 768.0f);
[sv addSubview:vc3.view];
[vc3 release];
What I want to be able to do is create an array of UIViewController and loop around the array to add them, rather than one by one. First off, I can't seem to create an array of UIViewControllers, my code is as follows:
NSArray *pages = [[NSArray alloc] initWithObjects:page1, page2, page3, nil];
and the error is: expected expression before 'page1'.
I did manage to load up the UIViewControllers with the following code:
for (int i = 1; i <= 3; i++) {
UIViewController *vc = [[UIViewController alloc] initWithNibName:[NSString stringWithFormat:#"page%i", i] bundle:nil];
vc.view.frame = CGRectMake((i-1) * 1024.0f, 0.0f, 1024.0f, 768.0f);
[sv addSubview:vc.view];
[vc release];
}
But even though the content from the XIBs was displayed, the viewDidLoad function of the loaded in UIViewControllers is never fired.
So, does any one have any tips here for loading up an array of UIViewControllers into a UIScrollView?
Thank you!
What is page1 *vc? Is page1 the name of your custom view controller class? It should start with a uppercase letter, i.e. Page1ViewController *vc.
Your array needs instances of the classes, not the classes itself.
NSArray *pages = [[NSArray alloc] initWithObjects:vc, vc2, vc3, nil];
But then, you shouldn't release the view controllers until you added them to your pages array, i.e. put [vc release]; [vc2 release]; etc. after your NSArray *pages = ...;