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;
Related
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
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 looking for a way to present a modal view over my current UIViewController to basically show a UIActivityIndicator and force users to wait while data is being loaded.
in BaseViewController.m (base class of all my UIViewControllers):
// show loading view
-(void) showLoading
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
LoadingViewController *loading = [storyBoard instantiateViewControllerWithIdentifier:#"loadingView"];
loading.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.7];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:loading animated:NO completion:nil];
}
This works great, but how can I go back to the background view after the loading view should be done?
Need a stopLoading method to go back to the original view:
// stop loading
-(void) stopLoading
{
// code here
}
If I try to present a new view after I present the loading view like so:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UIViewController *view = [storyBoard instantiateViewControllerWithIdentifier:#"loadingView"];
[self presentViewController:view animated:YES completion:nil];
The debugger gives Warning:
Attempt to present PropertyPickerViewController: 0x8af6010 on ViewController: 0x8ab23c0 which is already presenting LoadingViewController: 0x8acf530.
Try:
[self dismissViewControllerAnimated:YES completion:nil];
In fact, I'm not sure that it'a great idea to present new controller with animated gif.
The best option is (imo) show UIActivityIndicator + place a view on top on all other views to prevent user from clicking anything.
You must [self dismissViewControllerAnimated:YES completion:nil] first.
Check the Apple Documentation.
I'm trying to load my view then transition to it using a custom segue. The problem is that it's lagging quite a bit, and I can't seem to find the source other than the view being presented is loading during the segue.
- (IBAction)continueButtonClicked:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
IntroViewController *imageLoader = (IntroViewController*)[storyboard instantiateViewControllerWithIdentifier:#"imageLoader"];
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// present
[self customSegue:imageLoader];
// dismiss
[self dismissViewControllerAnimated:YES completion:nil];
});
}
I've gone to the extent of incorporating grand central dispatch, but I see no difference. I have little to no experience with GCD either. I have the same segue going to another view and it loads without lag just fine.
You can only present UI on the main thread and you are trying to do on a background thread. Try this:
- (IBAction)continueButtonClicked:(id)sender
{
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
IntroViewController *imageLoader = (IntroViewController*)[storyboard instantiateViewControllerWithIdentifier:#"imageLoader"];
// present
[self customSegue:imageLoader];
});
}
I've removed the [self dismissViewControllerAnimated:YES completion:nil]; line because dismissing the presenting view controller will result in the presented view controller not being able to unwind the segue.
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.