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()
Related
I have a back button on my answer view controller (a view controller that displays answers) if the user hits the back button I created it switches to a view that has the title of "Back" and just an empty tableview, before switching back to my main view of where all the questions to be answered are displayed. Why is this happening? Its a very brief thing, but definitely noticeable!
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 48)];
navBar.delegate = self;
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:#"Question"];
[navBar pushNavigationItem:topItem animated:NO];
topItem.leftBarButtonItem = nil;
[self.view addSubview:navBar];
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
return true;
}
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
You're creating your own UINavigationBar and UINavigationItem instances and you probably shouldn't be. The situation you describe is exactly what a UINavigationController is for. When using a UINavigationController it creates the UINavigationBar and each UIViewController that you show on screen (push into the navigation controller) has its own UINavigationItem (with the title taken from the title of the view controller).
The reason you get an empty 'view' titled "Back" is that you're creating it:
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
Dispense with all of this, create a UINavigationController and make your question view controller it's root view controller, then add the navigation controller to the screen. Then when a question is answered, push the answer view controller:
[self.navigationController pushViewController:answerViewController animated:YES];
I'm having a hard time trying to do something simple,
I have one viewcontroller that I want to use as a splash screen to the main menu viewcontroller. I can't figure why the modal is not called from the splash.
anybody have idea what is going on?
- (void)viewDidLoad
{
[super viewDidLoad];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0.0, 0.0, 180.0, 180.0);
indicator.center = self.view.center;
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
//prepare all resources for app
[indicator startAnimating];
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:#"mainMenu"];
mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainMenu animated:YES];
}
if I attach an button pressed event with the same code it works fine:
//[btn1 addTarget:self action:#selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
- (void)buttonPressedAction:(id)sender
{
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
MainMenuViewController* mainMenu = [sb instantiateViewControllerWithIdentifier:#"mainMenu"];
mainMenu.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainMenu animated:YES];
}
I changed the viewDidLoad to viewDidAppear and it worked fine. I don't know why though
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 managed to successfully change some of my UIView background to a custom image using
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myCustomBackground.jpg"]];
But it does not work on a particular view in a controller that is presented modally as such,
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:navController animated:NO];
[loginViewController release];
[navController release];
It seems like self.view inside this controller is behind the view it was showing.
EDIT
LoginViewController.m
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myCustomBackground.jpg"]];
}
self.view in this case seems to be hidden behind the current view that it's displaying. I did not add any subView beforehand.
As you mentioned in your comments, your view contains UIScrollView, UILabel and UIButton.
You should set to all this subviews property backgroundColor = [UIColor clearColor];. Hopefully that would help.
If you are editing subview in IB then you should find property Background in Attributes Inspector and select Clear Color (for all subviews).
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?