I want to embed an augmented reality controller into a custom view controller and i make this into viewDidLoad method of custom Controller.
These lines makes the job for me:
_arViewController = [[ARViewController alloc] initWithDelegate:self];
_arViewController.showsCloseButton = false;
[_arViewController setRadarRange:60];
[_arViewController setOnlyShowItemsWithinRadarRange:YES];
[self addChildViewController:_arViewController];
[[self view] addSubview:[_arViewController view]];
[_arViewController didMoveToParentViewController:self];
All work fine when i get into controller in Portrait mode and rotate the device.
Although when i get into controller in landscape mode and rotate the device in portrait the camera shows me only tha 1/2 of the view and the rest is blank.
If i replace the 3 last lines of the code above and push _arViewController to self.navigationController again all work fine for both orientations.
Can anyone help me with this issue? I prefer no to push the arController but have it into customViewController.
The project that i embedded into my App is the below:
iPhone -AR - Toolkit
First off all look at apple referce, it has some properties that might help you in block rotation: https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
In my point of view something like this may help you, just add method in .m file and implement correctly
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[_arViewController.view setFrame:self.view.frame];
}
Related
In my iOS 7/8 app, I have several viewcontrollers all of which should be portrait. I have a view controller which has a full screen view which will play video. I need this view to able to rotate depending on orientation of the phone. However the view controller that contains the video view is not allowed to rotate, reason being there are some other views sometimes overlaid above the full screen video view that are part of the viewcontroller and these should not be rotated.
So how can I rotate a single view and how do I get informed that the orientation of the device has changed. The usual [UIApplication sharedApplication].statusBarOrientation doesn't work as the viewcontroller itself does not rotate.
How to solve this problem.
Thanks
You can't rotate the screen forcefully. There is another way, in your case you have all the screens in Portrait, and you need a ViewController which can rotate both ways. You need to follow few steps described below.
See image for the settings you need to do in the Build Settings.
Create a Custom Class of type UINavigationController say CustomNavController, then in the .m class add the following code.
-(BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
Present the video controller as Modal using the CustomNavController, like below
VideoViewController *controller=[[VideoViewController alloc] initWithNibName:#"VideoViewController" bundle:nil];
CustomNavController *nav=[[CustomNavController alloc] initWithRootViewController:controller];
[self presentViewController:nav animated:YES completion:nil];
nav.navigationBar.hidden=YES;
And it should work, the trick is to separate rotations.
I am trying to add custom UIViewController on top of everything but not covering full screen (basically popover), like this:
- (void) displayPopoverController: (UIViewController*) content;
{
[self addChildViewController:content];
content.view.frame = [self frameForContentController];
[self.view addSubview:content.view];
[content didMoveToParentViewController:self];
}
Everything works, but unfortunately it is underneath the navigation bar. So I decided to add UIViewController to the navigation controller like this:
- (void) displayPopoverController: (UIViewController*) content;
{
[self.navigationController addChildViewController:content];
content.view.frame = [self frameForContentController];
[self.navigationController.view addSubview:content.view];
[content didMoveToParentViewController:self.navigationController];
}
It worked, but there are 2 problems:
1) viewWillAppear is not called when I add popover (only viewDidLoad is called)
2) If I change orientation, my popover receives notification and adjusts to new orientation, but UIViewController behind it does not. It will only update its view after I remove popover.
Is there any way to fix 1 and 2? Maybe there is better approach(I don't want to use UIPopoverController with custom UIPopoverBackgroundView)?
IMO you should make a custom transition and present UIViewController modally.
You can get help on Custom UIViewController transition here : http://www.doubleencore.com/2013/09/ios-7-custom-transitions/
I am trying to add custom UIViewController on top of everything but not covering full screen
If you can confine yourself to iOS 7, your problems are over. You can use presentViewController: and a custom transition to do exactly what you are trying to do. This, in my view, is the most important new feature of iOS 7: you can present a view controller's view only partially covering the main interface.
See my book; for the particular example code from the book, see https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p304customPresentedAnimation2/ch19p620customPresentedAnimation2/ViewController2.m
Plus I've now posted a single project at https://github.com/mattneub/custom-alert-view-iOS7. It shows how to make a view controller presented view that only partially covers the interface, plus it demonstrates that device rotation works correctly for all visible views (i.e. what's in front and what's visible behind).
On iOS6 I had a method to make one view controller in my navigation-style app auto rotate to landscape when I pushed it. (Basically present a bogus view controller and dismiss it in viewWillAppear).
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
if (![mVC isBeingDismissed])
[self dismissModalViewControllerAnimated:NO];
With the latest SDK this no longer works. Does anyone have another way to auto rotate?
Turns out the solution is simple, just pass YES to dismissModalViewControllerAnimated
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
if (![mVC isBeingDismissed])
[self dismissModalViewControllerAnimated:YES]; //Fix here
From Developer site
"When a view controller is presented over the root view controller, the system behavior changes in two ways. First, the presented view controller is used instead of the root view controller when determining whether an orientation is supported. Second, the presented view controller can also provide a preferred orientation. If the view controller is presented full screen, the user interface is presented in the preferred orientation. The user is expected to see that the orientation is different from the device orientation and rotate the device. A preferred orientation is most often used when the content must be presented in the new orientation."
I think here you can use the preferred orientation method here.
I am trying to implement a hide/unhide feature for the master view controller of my UISplitViewController. So the master view controller should be present in portrait and landscape mode but just for a specific view (the settings). Everywhere else it should appear in landscape only.
In -(void)viewDidAppear:(BOOL)animated of my MasterController I am writing
self.popoverController.delegate = self;
appDelegate.splitViewController.delegate= nil;
appDelegate.splitViewController.delegate = self;
[appDelegate.splitViewController willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
[appDelegate.splitViewController didRotateFromInterfaceOrientation:self.interfaceOrientation];
appDelegate.splitViewController.view setNeedsLayout];
The delegate method is also set
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO;
}
This approach I found here on stackoverflow really works well, but just as long as I rotate the device. Then the master view controller disappears (and leaves a black space). While rotating it appears and as soon as the rotation is done it disappears again. Further the master view controller disappears complelty if I click outside.
So I implemented the following delegate method to prevent the popover from disappearing
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
That works too, but then the tableView of my detail view is not responding.
If I delete the code from -(void)viewDidAppear:(BOOL)animated and the UIPopoverControllerDelegate method, it works all as expected, but just after I rotate the device.
So my question is, if anyone has an idea how I can solve that problem. The solution should be able to work with iOS 5.0 and newer.
Thanks a lot for your answers!
I am (still) in the process of converting an iPhone app to a universal app.
I want to push a UISplitViewController onto a UIView. As discussed here I am trying to create this flow:
UIView -> UISplitViewController (containing two UITableViews that I use in the iPhone version) -> UIView
I want the button attached to this IBAction to make the tableview appear on iPhone (which is all set up and working) and the SplitViewController appear on the iPad:
-(IBAction)makeStory:(id)sender{
NSLog(#"makeStory:");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//Code here to push split view.
} else {
//I am an iPhone!
makeStoryTableViewController = [[MakeStoryTableViewController alloc] initWithNibName:#"MakeStoryTableViewController" bundle:nil];
[self.navigationController pushViewController:makeStoryTableViewController animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
I've read tutorials here and here - but I can't get my head around how to add it to an existing app correctly. I would appreciate some help / direction so I can implement a UISplitViewController correctly in this universal app.
You can't "push" a split view controller or add it on top of another view. It has to be the root view controller of the window.
In your IBACtion you could do something as simple as:
appWindow.rootViewController = aSplitViewController;
Of course, you have to get a reference to your app's window, and you have to get aSplitViewController which is initialized with left and right view controllers from somewhere...