I have draw a view inside my storyboard that have 300x350 pixels, I want to present this view inside my current view (600x600 pixels and is a initial view controller), for this I try this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ModalViewController *viewController = (ModalViewController *)[storyboard instantiateViewControllerWithIdentifier:#"modalView"];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:viewController animated:YES completion:^{
viewController.view.superview.frame = CGRectMake(0, 0, 300, 350);
viewController.view.superview.center = self.backgroundColorView.center;
}];
This code have two problems:
My view load in full screen and have a delay that changes the screen size to 300x350 pixels.
Outside of my view I can see a black screen (In my case was supposed to appear the part of my other view).
How can I solve this problem? (I'm not using navigation controller)
You need to change modalPresentationStyle to be overCurrentContex
Related
I have created storyboard which I want to open on top of another view or in childView so that when I close or destroy this view of storyboard the earlier view on which the storyboard is opened remains the same.
When I run the following code:-
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[[UIApplication sharedApplication].keyWindow setRootViewController:detailViewController];
First, the storyboard opens but I don't know whether it opens on top of previous view or it destroys the previous view & then open.
Second, the functions needed on that storyboard runs automatically which is as I want but how these things are working.
If anyone can help me understand the above code and its working.
NOTE: I cannot call the earlier view again in same state because of some reason.
Thanks in Advance!!
Here you are setting root view controller
it will not keep your back screen as it is what you want
If you want to keep current screen and show other screen on that
you have two approaches
1) Present ViewController
2) Push View Controller
1) Present ViewController
for this you can present your screen on top of other screen which is visible
for example
- (IBAction)btnNextTapped:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[self presentViewController:detailViewController animated:true completion:nil]
}
2) Push View Controller
For that you need NavigationController and need to push your ViewController from current visible screen
i.e
[self.navigationController pushViewController:vc animated:true];
EDIT
as per discussion you need to find current top view controller then you should present it
Add this method below your method
- (UIViewController*) topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
And Replace this method with code
- (void)goToNewPage:(CDVInvokedUrlCommand*)command
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[[self topMostController] presentViewController:detailViewController animated:true completion:nil];
}
need help in adding search bar ViewController which whose SearchBar will be in NaviagationBar with Back button (navigation search i achieved - self.navigationItem.titleView = searchBarView) throughout app, but until it has search i want to show previous ViewController in background with semi-transparent black color just like i achieved in Android :
i can add semi-transparent ViewController to current ViewController :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
[vc setTransitioningDelegate:transitionController];
vc.modalPresentationStyle= UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
but what it is doing that it opens SecondViewController in transparent without NavigationBar, the FirstViewController has NavigationBar
And when the SecondViewController is opened it should have SearchBar in NavigationBar and it shouldn't be Transparent as i achieved in Android.
There will be n number of ViewController which will add this same controller as Overlay Controller with NavigationBar and back button.
Please Help.
I found some solutions which involve taking a snapshot of the view and adding them to your navBar controller.
From Apple:
https://developer.apple.com/library/ios/qa/qa1817/_index.html
Other interesting option:
iOS iPhone is it possible to clone UIView and have it draw itself to two UIViews?
In you code snippet you just create new SecondViewController and present it like modal. It appears without navigation bar because you create it without Navigation Controller.
If you want to keep SecondViewController in the same navigation stack as previous ViewController with navigation bar and default Back button you should call:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self presentViewController:vc animated:YES completion:nil];
[self.navigationController pushViewController:vc animated:YES];
To make SecondViewController like semitransparent, take screenshot of previous view controller, pass this image to SecondViewController and use it like background. You can apply this image to additional ImageView on your SecondViewController view or just call:
self.view.backgroundColor = [UIColor colorWithPatternImage:self.backgroundImage];
I'm attempting to present a VC modally that shows a blur of the previous view controller. This is my attempt. The problem is that this only works maybe 50% of the time. Half of the time the blur works as intended, the other half I only get the grey blur as if the background is black (no background content).
-(void)plusButtonPressedOnCell:(SASearchTableViewCell *)cell
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"ActionMenu" bundle:nil];
SAActionMenuViewController *actionMenuVC = (SAActionMenuViewController *)[storyboard instantiateInitialViewController];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:actionMenuVC animated:NO completion:^{
//animations
}];
}
Any ideas why this is happening?
My presentation style was incorrect, and I was attempting it on the wrong view controller. This was the fix.
This line:
self.modalPresentationStyle = UIModalPresentationCurrentContext;
needed to be:
actionMenuVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
I'm trying to implement a UIModalTransitionStylePartialCurl on a viewController to present a partial view of ViewController2 (I am using xCode 4.6 with storyBoards for a universal app). The following code does animate the UIModalTransitionStylePartialCurl but shows only a black window underneath. So, it works (no crash) but it won't present/show the second view ??
ViewController2 *v2 = [[ViewController2 alloc]init];
v2.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:v2 animated:YES completion:NULL];
You haven't initialized v2 . you should use this :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Your_storyboard_name" bundle:nil];
ViewController2* v2 = [storyboard instantiateViewControllerWithIdentifier:#"Your_view_controller_identifier_from_storyboard"];
v2.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:v2 animated:YES completion:NULL];
Do any additional checks to see if it's iPad or iPhone and fill the information as is required.
I am creating a viewcontroller in this way:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"PhotoViewControlleriPhone" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
vc.view.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y + 64, imageView.frame.size.width, 200.000000);
vc.view.layer.cornerRadius = 10; // this value vary as per your desire
vc.view.clipsToBounds = YES;
The viewcontroller is not full screen, so you can still see the previous one. I want to be able to see it, but lock it. Just like when you use ios facebook sharing, you see the background, but it becomes darker and you can't interact with it. How can I do this?
I believe the problem is that you’re displaying it using -presentModalViewController:animated:. Using that method carries with it some assumptions about the view controller you’re hosting; one of the assumptions it makes (on iPhone-type devices, at least) is that the view controller takes up the entire screen and is opaque.
To get around this, try adding the modal view controller’s view to the current view controller’s view manually. You’ll need to set the view controller hierarchy up to match the view hierarchy, so your code would look like this:
[self addChildViewController:vc];
[self.view addSubview:vc.view];
You’ll need to adjust the incoming view’s frame to position it within its new superview, but that should allow you more freedom.
My workaround is to take a screenshot with code, pass the UIImage as a parameter to the new UIViewController, and display it as a background image. In that way it appears transparent, and the you don't have to disable the underlying controls that might be reachable/accessible.
iOS8+
You can use below code snippet for iOS8+, its worked for me
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:secondViewController animated:YES completion:nil];