Flip landscape UIViewController - objective-c

I have a button in my UIViewController, I want to have Flip transaction when I press the button, I have transaction but it's flip portrait, would you please help me!
I want to have it as Landscape
here is my code :
TestViewController *ctrl = [[TestViewController alloc] init];
[UIView transitionFromView:self.view
toView:ctrl.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:nil];
[self.navigationController pushViewController:ctrl animated:NO];
Thanks in advance!

What you're doing is illegal in any case. You may not transition your own view (self.view) out of the view hierarchy. Either transition a subview of self.view to a different subview of self.view, or else, if you want to use views belonging to view controllers, set up a system of parents and children and manage them properly (and, in general, call transitionFromViewController:toViewController:duration:options:animations:completion:).
If what you're trying to do is summon the view of a different view controller, then use one of the methods that does that, such as presentViewController:animated:completion:.

Related

Mimic modal window to allow for tapping outside of modal window

I am using a Split View Controller and showing a modal window when a button is tapped in the master pane. I need to be able to dismiss the window when the user taps outside of the bounds of the window.
I am currently using presentViewController, which I have read does not allow for taps outside of the window.
I think I need to present a view controller myself and setup a gesture recognizer to handle the closing from there... the trouble is, I don't know where/how to present the view controller or where to attach the gesture recognizer to in an SVC.
I setup my view controller like this:
SearchViewController *searchViewController = [[SearchViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:searchViewController];
[navController setNavigationBarHidden:NO];
From there I don't know how to make the view controller appear without using presentViewController. I have tried the following (each separately):
[[self navigationController] addChildViewController:navController];
[self.view.window.rootViewController addChildViewController:navController];
[self.presentingViewController addChildViewController:navController];
[self.presentingViewController.presentingViewController addChildViewController:navController];
How do I present my navcontroller, and which view would I add a gesture recognizer to?
A UIPopoverViewController will work.
Alternatively, you can add a child view controller to your RootViewController. . (Check out UIViewController containment for lifecycle handling).
Basically just this in your root view controller:
- (void) presentSemiModalViewController
{
//Tint-out the background or blur it with some effect
_semiModalViewController = viewController;
//Choose the frame you'd like to use here, and an animation you'd like to use to present it
[self.view addSubView:_semiModalViewController.view];
[_semiModelViewController willMoveToParentViewController self];
}
If the RootViewController is not yours (eg a UINavigationController) you can use a category, but to retain the _semiModalViewController you'll need to use an associative reference (ie add a "property" to the category to store the modal VC while its in use). For info on that see here: Associative References Info
PS: You might want to choose a better name my "semi-modal", but you get the idea ;)

What exactly is navigationController.view.superview?

My project has existing code in several places where it uses navigationController.view.superview.frame and navigationController.view.superview.center to size and center modal views on top of current view. Sure I can use them as boiler plates but honestly I have no idea what navigationController.view.superview really refers to. Is it particular to UINavigationControllers? Any ideas/comments would be appreciated.
[Edit] Here's the code:
UIStoryboard *sb = self.storyboard;
MyViewController *vc = (MyViewController *)[sb instantiateViewControllerWithIdentifier:#"MyLoginViewController"];
vc.delegate= self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.navigationController presentModalViewController:navController animated:YES];
navController.view.superview.frame = CGRectMake(
navController.view.superview.frame.origin.x,
navController.view.superview.frame.origin.y,
400.0f,
400.0f
);
navController.view.superview.center = self.view.center;
If I don't use navigation controller for the new modal view, I wouldn't have to use "superview". Namely,
UIStoryboard *sb = self.storyboard;
MyViewController *vc = (MyViewController *)[sb instantiateViewControllerWithIdentifier:#"MyLoginViewController"];
vc.delegate= self;
[self.navigationController presentModalViewController:vc animated:YES];
vc.view.frame = CGRectMake(
vc.view.frame.origin.x,
vc.view.frame.origin.y,
400.0f,
400.0f
);
vc.view.center = self.view.center;
However, I wouldn't be able to view the presenting vc in the background...
navigationController - This is, well probably a UINavigationController. I say probably because you've not given any context so I can only assume that from the name.
navigationController.view - The navigation controller's view.
navigationController.view.superview - The navigation controller's view's superview. i.e. the view that the navigation controller's view sits in.
navigationController.view.superview.frame - The navigation controller's view's superview's frame. i.e. the frame (position and size) of the view the navigation controller's view sits in.
navigationController.view.superview.center - The navigation controller's view's superview's centre. i.e. the centre (position of the centre point) of the view the navigation controller's view sits in.
It's ugly to use these properties directly like that. I can't conceive of why you would want to ever go hunting into the depths of the view hierarchy like that to do anything. This to me is a bad smell. I suggest finding the right way of solving the problem.
In most cases, that probably refers to your instance of UIWindow. If you're trying to center things on screen, you can get the rect of the device's screen using [UIScreen mainScreen].applicationFrame.
As explained in the documentation for UIView, the method -superview returns the view's superview in the view hierarchy. That is, the superview is the view that contains the navigation controller's view. This is not specific to UINavigationController.

Is this the right way to add a view?

I make a program that shows a table.
If people click the search I will add another view covering the original view. The original view is [BNUtilitiesQuick listnewcontroller];
[[BNUtilitiesQuick window] addSubview:[BNUtilitiesQuick searchController].view];
[[BNUtilitiesQuick searchController] viewWillAppear:YES] is indeed called. So it seems that UIView has a pointer to it's controller
However, the view that the [[BNUtilitiesQuick listnewcontroller] viewWillDisappear] is not called
Moreover, [[BNUtilitiesQuick listnewcontroller] viewWillAppear] is also not called even when the user has finished modifying search term with this code:
[self.view removeFromSuperview];
I think I may be missing something here. What exactly should I do anyway so IOs knows that the searchController.view will be covering listNewController?
This is NOT the right way to do it. If the searchController is a full screen controller you should present it modally using presentViewController or push it onto the navigation stack as #StuR suggested.
In case your search view covers only part of the listnewcontroller you should use the containment API in iOS5.
Inside listnewcontroller (parent view controller) you would write:
[self addChildViewController:self.searchController];
[self.view addSubview:self.searchController.view];
[self.searchController didMoveToParentViewController:self];
For more in-depth information check out the WWDC 2011 session video "Implementing UIViewController Containment". Also watch "The Evolution of View Controllers on iOS" from 2012 because there are some changes and deprecations in iOS6.
ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
I'd consider using pushViewController for adding a full screen view. addSubview is for views that don't cover the entire screen.
viewWillDisappear and viewWillAppear will only me called if you pop or push the given viewController. You are simple adding a subview with it's own viewController inside(on top) of the present viewController. As StuR said, if you want to dismiss the current ViewController you should use:
BNUtilitiesQuick *searchController = [BNUtilitiesQuick alloc] init];
[self.navigationController pushViewController:searchController animated:YES];
You can read more about ViewControllers here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457

UIModalPresentationFullScreen not working in iPad landscape mode?

I have added a ViewvController(B) as subview on ViewController(A). In ViewController A(SuperView) UIModelPresentationFullScreen working fine. But when am calling UIModelPresentationFull in ViewController B(SubView) it modelview showing in Portrait mode and that is also not fully viewed. How to solve this problem. Can any one help me please. I have tried 2 days.
This is what I tried in both the superview and subview...
picFBCapture *fbCapt = [[picFBCapture alloc] init];
//[self.navigationController pushViewController:fbCapt animated:YES];
//fbCapt.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
fbCapt.modalTransitionStyle = UIModalPresentationFullScreen;
[self presentModalViewController:fbCapt animated:NO];
[fbCapt release];
Thanks in advance..
The problem is that if you add a view controller as a subview it's not connected to the view controller hierarchy and thus certain things doesn't work. You should avoid adding view controllers as subviews whenever possible, since this is not how Apple intend view controllers to be used, but sometimes it can't be avoided.
If this is one of those cases when it can't be avoided you should save a reference to view controller A in view controller B and then call presentModalViewController: on view controller A (that is connected to the view controller hierarchy) instead of self (view controller B, that isn't connected).
EDIT: In controller A you probably have code looking something like:
[self.view addSubview:controllerB.view];
In conjunction to this line add:
controllerB.controllerA = self;
I hope you know how to create properties, but if not here's a hint:
#property (nonatomic, assign) UIViewController *controllerA;
The rest you should be able to figure out using Google and the documentation.
You will have to handle viewController B's view in landscape by yourself. Since viewController B has been added as a subview, its view controller will not be handling its landscape orientation. The UIModalPresentationFullScreen style (landscape and portrait) will work only if viewController B is shown, ie not as subview but as a full view itself.

presentModalViewController ontop of subview?

I am trying to recreate the iPhone's tabView, but with my own style, buttons, etc. I didn't want to have to totally redo my app, so I simply added a view to the bottom like this [window addSubview:theToolbar]; theToolbar.frame = CGRectMake(0, 425, 320, 44); in my appDelegate.
However, when trying to do this from a view inside a navigationController theToolbar is over it. Is there anyway to somehow present it to the front?
Here's my code to present the view:
AppSettingsController *appSettings = [[AppSettingsController alloc] initWithNibName:nil bundle:nil];
appSettings.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:appSettings animated:YES];
[appSettings release];
Thanks.
it's impossible show partial views of the viewcontroller. if your want to use the same toolbar, you should retain the toolbar to your appdelegate, and add the toolbar to each viewcontroller when it is in view.
or you should just use uiview's as viewcontrollers