Presenting a view controller of custom size with navigation - ios

I want to present a view controller of custom size say (500,500). I try to do that with the below code, it works fine with a semi transparent light gray background if I present the view controller alone but when i put the view controller in a navigation controller (which I want to do) there is a black background that comes up, I dont want this and I want the gray one.
I did the following code with the help of this question:
iOS -- how do you control the size of a modal view controller?
MyViewController *vc=[[MyViewController alloc]initWithNibName:#"MyViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];
nav.modalPresentationStyle=UIModalPresentationPageSheet;
[self.window.rootViewController presentModalViewController:nav animated:YES];
CGRect r = CGRectMake(self.window.rootViewController.view.bounds.size.width/2 - 250,
self.window.rootViewController.view.bounds.size.height/2 - 250,
500, 500);
r = [self.window.rootViewController.view convertRect:r toView:vc.view.superview.superview];
vc.view.superview.superview.frame = r;
Any guess, what I am missing here?? Or is there a easy way to present a custom size VC with navigation??
With navigation:
Without navigation: (i am using a dark background, so it may appear like it is black but it is not)

Just putting transparent overlay on the view controller and present it, sothat it looks like as what you actually want...
Also refer the following link,
Show modal view controller with custom frame in iPad
How to present a modal view controller with custom size in center?
iPad custom size of modal view controller
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

Related

pushViewController:animated: doesn't fully animate current controller out of bounds

I have a UINavigationController thats width is 255 and the rootViewController is a UITableViewController that is of the same width. The problem is that when I push a new view controller, the current rootViewController animates about 1/3 of the way off screen and then stays visible while the new controller comes in and then it disappears. If I set animated to NO it works fine, but I need to animate it. There isn't anything fancy going on in the code, it is a simple push/pop setup when switching controllers. I added a video below to show you what it looks like. I put borders on the navigation controller (blue) and table view (orange). The code that does the push/pop is:
if ([[self.menuNavigationController topViewController] isKindOfClass:[TeamMenuViewController class]])
{
[self.menuNavigationController pushViewController:self.teamsViewController animated:YES];
}
else
{
[self.menuNavigationController popToRootViewControllerAnimated:YES];
}
It looks like your viewController.view that is being pushed on has a transparent background. The default UINavigationController animation in iOS 7 and 8 has an overlap effect.

How to make a DejalActivityView over a popover view

I have a split view controller within a navigation controller and I want to put a DejalActivityView over everything it when I'm doing certain operations. Right now I'm using the following code:
- (void)showActivityView
{
UIView *viewToUse = [MSMasterViewController get].splitViewController.navigationController.view;
[DejalBezelActivityView activityViewForView:viewToUse];
[DejalActivityView currentActivityView].showNetworkActivityIndicator = YES;
}
This works in landscape mode, but when in portrait mode with the master view in popover form, the dejal activity view appears behind the popover. Is there a better view to use that will cover the whole screen?
Maybe you could use your Window as Superview, and only change relativ Frame positing.
greetings Oli

How can I add a transparent view?

I want to push a view controller onto the navigation stack but I don't want its view to initially appear - in other words I want the view that was visible when the view controller is push to still be visible.
I tried setting the view controller's view's alpha value to 0.0 which I thought would make it transparent. But instead what is happening is that when I push the view controller on the the stack the screen is white. If I set the alpha to 1.0 then the view controller's view appears as expected.
Why is it white and not transparent?
you will have to add the view to the viewcontrollers manually
Not pushing it
For example do the following
YourViewController *vc = [[YourViewController alloc] init];
[self.view addSubview:vc.view];
vc.view.alpha = 0.0;
//Animate Here
vc.view.alpha = 1.0;
//Commit Animate Here
Please not that you will have to do some additional coding to implement the release of the vc, since now you have retained vc.view you will not be able to release vc easily,
Another solution is instead of implementing the second view as a viewcontoller implement it as uiview, and the xib class will be view and not uiviewcontroller
Maybe make sure that the opaque property is set to NO?
Or perhaps the view you're pushing on was built in interface builder, and you have a background color of white with another view you put on top of it and you only changed the opacity of the subview?

With UIPresentationFormSheet, why doesn't my view move above the keyboard when it is up?

Apple says:
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
But my view doesn't move up when the keyboard is visible. I basically want to present a textview modally above the keyboard so the user can enter text and then hit send (in a nav bar button on the presented view.)
My presenting view is a UISplitViewController (not one of its children) and I'm presenting UINavigationController who's top view controller is basically a UITextView. Rotation works, but the presented view is overlapped by the keyboard in both orientations.
I found some questions asking how to resize the presented view in this case, which is nice, but I don't want to have to make assumptions by resizing manually in the presenter or in the presented view. It seems like it should just pick a decent (undocumented) size just move it up automatically when the keyboard shows.
My presenting code looks like this:
MyViewController *vc = [[MyViewController alloc] init];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentModalViewController:nav animated:YES];
As I was finishing up my question, I realized I was calling becomeFirstResponder on my UITextView in viewWillAppear. If you change it to viewDidAppear it will work, which makes sense.

Display Modal View Controller over detail view in UISplitViewController

I have a UISplitViewController in an iPad app. When something is selected from the table I want to fade in a modal view controller over the detail view. I can present it without a problem, but for some reason I can't get it to match the frame of the detail view. I would like it to stick to the detail view controller frame on rotation as well. Does anyone have any experience with this? This is my code to display. The detail view controller reference is set in the app delegate and passed down the table controllers.
QuestionViewController_iPad *questionView = [[[QuestionViewController_iPad alloc] initWithNibName:#"QuestionViewController_iPad" bundle:nil] autorelease];
questionView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Not quite
questionView.modalPresentationStyle = UIModalPresentationCurrentContext;
questionView.questionQuizCon = [QuestionQuizConnection firstQuestionForQuiz:quizCatCon.quiz];
// Maybe something like this?
[self.detailViewController presentModalViewController:questionView animated:YES];
When the modal view presents, it matches the size of the detail view controller, but it doesn't but it sits on the top left of the screen behind the master view controller. It also doesn't resize on rotation. I have the springs and struts set to auto size and fill. The height changes on rotation but it won't fill the width.
I couldn't get this to look right any way I tried it so I ended up just using view transitions to make it look like pages being torn off a notebook. That looks better anyway.
// Transition the view on as a subview.
[UIView transitionWithView:self.detailViewController.pageView duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^ {
questionView.view.frame = CGRectMake(0, 0, self.detailViewController.pageView.frame.size.width, self.detailViewController.pageView.frame.size.height);
[self.detailViewController.pageView addSubview:questionView.view];
// Watch this one
self.detailViewController.currentQuestionViewController = questionView;
}
completion:nil];
After [self.detailViewController presentModalViewController:questionView animated:YES]; you should set center property and/or frame of questionView. Be sure that you set it after presenting modal view.

Resources