I want to use UIModalPresentationFormSheet in my app. But i'm using navigation controller. So when i writes following code it is not responding me. What should i do ?
[self.navigationController pushViewController:controller animated:YES];
Try something like this:
// assume controller is UIViewController.
controller.modalPresentationStyle = UIModalPresentationFormSheet;
Then
[self.navigationController presentModalViewController:controller animated:YES];
Check with the below sample working code.
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after
presentModalViewController targetController.view.superview.center = self.view.center;
Taken from -->
How to resize a UIModalPresentationFormSheet?
Related
I have a code like this in my fist viewController :
- (IBAction)showSetting:(id)sender{
settingView = [[settingController alloc]initWithNibName:#"settingController" bundle:nil];
settingView.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:settingView animated:YES];
}
and then in the second view (settingController.m) :
- (IBAction)closeSetting:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
I want to set the transparency of background while showing the present modal, but it shows a blank black screen.
is there anyone can help me..
Like You have a rootViewController which will present your settingView .
settingView .view.backgroundColor = [UIColor clearColor];
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootViewController presentModalyourViewController:settingView animated:YES];`
UIModalPresentationCurrentContext with Transition
settingView .modalPresentationStyle = UIModalPresentationCurrentContext;
settingView .modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
try this
- (IBAction)showSetting:(id)sender{
settingView = [[settingController alloc]initWithNibName:#"settingController" bundle:nil];
settingView .view.backgroundColor = [UIColor clearColor];
settingView .modalPresentationStyle = UIModalPresentationCurrentContext;
settingView .modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalyourViewController:settingView animated:YES];
}
Please use this
settingView *settingViewObj=[[settingView alloc]initWithNibName:#"settingView" bundle:nil];
UINavigationController *nController = [[UINavigationController alloc]initWithRootViewController:settingViewObj];
[nController setNavigationBarHidden:NO];
[self.navigationController presentViewController:nController animated:YES completion:nil];
But this is the code for iOS 6.For iOS 5 you can use
[self.navigationController presentModelViewController:nController animated:YES];
Hope this helps
As others explained above, you can do it with a Modal presentation using:
settingView .modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
However, if you see a different color coming from behind is because your window has that color. Try setting the background color of your window (normally on your AppDelegate):
window?.backgroundColor = UIColor.whiteColor()
I have the following problem. I want to go from a view to another view, not with a button, but writing code. I have a view in which there are, among other things, some buttons. When I press one of them runs an if - else. From else I want to go to another view.
I have tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view insertSubview:gOver.view atIndex:0];
and this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view addSubview:gOver.view];
but nothing worked. Any ideas ?
i also tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view setHidden:YES];
[self.navigationController pushViewController:gOver animated:NO];
throws exeption on
[self presentModalViewController:gOver animated:YES];
[self.view insertSubview:gOver.view atIndex:0];
[self.view addSubview:gOver.view];
Thanks in advance
DonĀ“t call [self.view removeFromSuperview]; which may cause your viewController to be deallocated, when using presentModalViewController it covers your view:
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
// gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
If you need to hide your current view then use: [self.view setHidden: YES];
"I want to go from a view to another view, not with a button, but writing code." - did you refer this to push in storyboard or did you mean that you din't want it in a button action?
The above code works fine :
-(IBAction)buttonAction:(id)sender
{
GameViewController *game = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil];
game.modalTransitionStyle = UIModalTransitionStylePartialCurl ;
[self presentModalViewController:game animated:YES];
}
And hope that you doing n iPhone app and not an iPad one, in which case you need to use popOver instead of modalView
I have even tried implementing a delay right before the call to popToRootViewControllerAnimated however that does no good either. It just does not get called.
-(IBAction) btnSignOut{
[[self tabBarController]setSelectedIndex:0];
[[self navigationController]popToRootViewControllerAnimated:NO];//DOES NOT GET CALLED
Overview *overviewController = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
//Lets place OverView in navController
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:overviewController];
// [[self navigationController] popToViewController:ComposeViewController animated:YES];
//Now lets display it
[self.tabBarController presentModalViewController:navController animated:YES];
[navController release];
[overviewController release];
}
It seems like the [self navigationController] does not contain any view to pop
I have a view which pulls in another view using this code:
secondView = [[SecondView alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondView];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
The cancel button on this 2nd view has this:
[self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
But it doesn't appear to do anything. The view is still there and I can still interact with it. How do i remove it?
try:
[self.navigationController dismissModalViewControllerAnimated:YES]
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.view.frame = CGRectMake(0, 20, 320, 400);
//unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelBtn.frame = CGRectMake(262, 6, 54,30);
[unknownPersonViewController.view addSubview:cancelBtn];
[self presentModalViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
i am using UIViewcontroller and in this code i want that a bar like navigation bar will show in upper
side of this controller so i want to put cancel button on that bar.any help?
What you should do is embed your ABUnknownPersonViewController in a UINavigationController
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:unknownPersonViewController];
[self presentModalViewController:newNavigationController animated:YES];
[view release];
[newNavigationController release];
That way you wouldn't even have to add the button yourself, the ABUnknownPersonViewController would take care of it for you.
For more info check Address Book Programming
Hmm, the online documentation says "Important Unknown-person view controllers must be used with a navigation controller in order to function properly." So, unlike a lot of the utility view controllers, I don't think you should be invoking
[self presentModalViewController:unknownPersonViewController animated:YES];
But rather
[self.navigationController pushViewController:view animated:YES];
I think if you look at their samples, you'll see they push using the navigation controller.