Modalviewcontroller is showing gap after loading. Gap is after staus bar which moved modalviewcontroller down and gap shows me main window. So how i can remove this gap which is showing between status bar and modalviewcontroller. There is no interface builder involved. Creating everything programmtically. Help for this will be really appreciated.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
[button addTarget:self action:#selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:button];
- (void)displayModalViewaction: (id) sender
{
self.viewController = [[Infoviewcontroller alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] init];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[self.view addSubview:navigationController.view];
}
Thanks
In your _viewController, you need to update this code if you want to hide the gap -
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
But ideally it needs to be fixed by-
[self presentModalViewController:navigationController animated:YES];
Not sure why it is not working for you.
Assuming this code is in a UIViewController you probably want to do something like this.
self.viewController = [[[Infoviewcontroller alloc] init] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
By adding the view frame size [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; fixed the gap between status bar and modal view.
Related
Currently I'm using my own custom images in UIBarButtonItems with the following code:
UIButton *profileBarButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35.0f, 35.0f)];
[profileBarButton setImage:[UIImage imageNamed:#"profile-barbutton.png"] forState:UIControlStateNormal];
[profileBarButton addTarget:self.navigationController action:#selector(toggleMenu) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:profileBarButton];
This works perfectly when I have a defined action to call, such as presenting a modalviewcontroller and turning on edit mode. However, I'm confused as to how I'd set the action for going back from one view to another, not modally? Is there a specific method I could call programmatically? Usually the navigationcontroller takes care of this...
for going back from one view to another, not modally you may write like this:
- (void) toggleMenu
{
if (self.navigationController.visibleViewController == self)
{
[self.navigationController popViewControllerAnimated: YES];
}
}
Use this code:
[self dismissViewControllerAnimated:YES completion:nil];
Check with this code...
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyNib" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController:nc animated:YES];
[vc release];
[nc release];
Then normally push code like...
OtherViewController *vc = [[OtherViewController alloc] initWithNibName:#"MyOtherNib" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
:)
Try this code:
UIImage *backButtonImage = [UIImage imageNamed:#"backButton.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBackBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = customBackBarItem;
In the #selector(back), "back" is the method that triggers the popup method of navigationcontroller. Like this:
-(void)back {
[self.navigationController popViewControllerAnimated:YES];
}
I am using the below statement to define the transitionstyle
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
in the below code but the above statement is not flipping horizontally while presenting it modally
#property (nonatomic, assign) UIModalTransitionStyle *modalTransitionStyle;
#synthesize modalTransitionStyle;
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
_viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:_viewController animated:YES];
Anyone knows that why it is so. When everthing is coded programmtically.
Thanks for help though.
There's a lot of confusing naming going on here.
AFAICT, _viewController is the root view controller of your navigationController. But you reference self.viewController... is this the same view controller? If so, why are you not consistently using accessor methods? If not, it's not clear to me that you setting the modal transition style on the correct view controller ([self viewController] vs. _viewController).
(Btw, please work on formatting your code so that it displays in a more reasonable way when you paste it in.)
Wrong way to approach the problem. I suggest you to review your code in order to improve readability and maintainability.
Supposing that you've a viewcontroller with a target action associated with a button, something like this:
...
[aButton addTarget:self
action:#selector(dismissView:)
forControlEvents:UIControlEventTouchUpInside];
...
You can write a selector method, in order to display your new viewcontroller as follow:
- (void)dismissView:(id)sender {
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:secondVC animated:YES];
[secondVC release];
}
How can I vertically flip a UIViewController which is presented modally along with a UINavigationController and Done Button.
This is how I am presenting the UIViewController modally:
- (void)modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds] autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[self.view addSubview:navigationController.view];
[navigationController release];
}
How can I flip this UIViewController whilst presenting it modally?
Thanks for your help.
You can specify the desired animation technique by setting the modalTransitionStyle property (before presenting the view controller).
Unfortunately this property can be set only to:
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
So vertical flip it is not supported.
Take a look at UIModalTransitionStyle reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
When i press the infobutton on the mainviewcontroller it shows navbar and uitextview modally but doesn't shows done button.
- (void) modalViewAction:(id)sender
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
navigationController.navigationBar.tintColor = [UIColor brownColor];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(Done:)] autorelease];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[navigationController release];
Anyone have ideas why is that Done Button is missing from the navigationcontroller.
Thanks for help.
Your presenting it Modally:
[self.navigationController presentModalViewController:self.viewController animated:YES];
You need to push it onto the navigation stack:
[self.navigationController pushViewControler:self.viewController animated:YES];
Now the NavigationController will take care of the back button for you.
You have to either:
push the view controller onto the navigation controller (as Hubert
explained), or
create a new UINavigationController and set the
viewController as the rootViewController of that
UINavigationController and then you can do:
[self.navigationController
presentModalViewController:newNavigationController animated:YES];
I added following statement
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
to the below code and now Done button is showing on the navigation controller
- (void) modalViewAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_viewController = [[ModalViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:#selector(dismissView:)] autorelease];
[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[self.navigationController presentModalViewController:self.viewController animated:YES];
[self.view addSubview:navigationController.view];
[navigationController release];
}
So my issue is solved.
Thanks for help
I used the codes below to display an view(ViewController) on window.
ViewImagesController *vvViewImagesController=[[ViewImagesController alloc] init ];
self.vViewImagesController=vvViewImagesController;
[vvViewImagesController release];
UINavigationController *a=[[UINavigationController alloc]initWithRootViewController: vViewImagesController];
[self.view addSubview:a.view];
but the navigation bar appeared underneath the status bar 20 points.
Even I use the codes:
[a.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
to relocate the view, but the result is same.
Welcome any comment
Here's what you need to do. It's 1 line and it works:
In viewDidLoad in vvViewImagesController:
[self.view setFrame: [self.view bounds]];
Whoosh!
try instead
ViewImagesController *vvViewImagesController = [[ViewImagesController alloc] init];
UINavigationController *a = [[UINavigationController alloc] initWithRootViewController:vvViewImagesController];
[self presentModalViewController:a animated:YES];
[vvViewImagesController release];
[a release];