I have a parentViewController that calls a modal ViewController with Delegate UITableViewController. The problem is that I do not have navigation stack to get the value from the parent's shouldAUtoRotate.
Since the shouldAutorotate never fired it gets it from a main controller where return NO and this cannot be changed. Is there a way to manipulate the modal controller to get the proper shouldAutorotate set to YES?
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.pv dismiss:YES];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
//[self fullScreenAction:nil];
} else {
// [self exitFullScreenAction:nil];
}
}
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
//ios >=6
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ||
(interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
I managed to solve my problem although is not the best solution, maybe for some will be useful.
So i create a new Category Controller in order to use it to set manually the Rotation calls.
.m
#import "UINavigationController+AutoRotate.h"
#implementation UINavigationController (AutoRotate)
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskAll;
}
#end
and .h
#import <UIKit/UIKit.h>
#interface UINavigationController (AutoRotate)
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
#end
And then the Modal was working as it should without a navigation controller.
Related
In OS X sierra 10.12 Drag and drop is not working properly with NSTabView....
Drag and drop seems to only work in label of TabView not the entire tab ..you can see in the following project sample...download Code
OR here is code:-I have created a subClass AppMainTabSet OF NSTabView and use this class as a custom class of TabView In Interface Builder.....
#import "AppMainTabSet.h"
#implementation AppMainTabSet
- (id)initWithCoder:(NSCoder *)coder
{
/*------------------------------------------------------
Init method called for Interface Builder objects
--------------------------------------------------------*/
self=[super initWithCoder:coder];
if ( self ) {
}
return self;
}
- (void)awakeFromNib{
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
}
-(NSDragOperation) draggingEntered:(id < NSDraggingInfo >)sender
{
NSLog(#"Hello Hello....draggingEntered");
return NSDragOperationGeneric;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
NSLog(#"**** draggingExited*****");
}
- (BOOL) prepareForDragOperation:(id <NSDraggingInfo>)sender {
NSLog(#"Hello Hello....prepareForDragOperation");
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(#"Hello Hello....performDragOperation");
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
NSLog(#"Hello Hello....concludeDragOperation");
[[NSCursor arrowCursor] push];
[self setNeedsDisplay:YES];
}
- (BOOL) processNSDraggingInfo:(id <NSDraggingInfo>)sender {
NSLog(#"Hello Hello....processNSDraggingInfo");
return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
view1=[[BIDViewController alloc]initWithNibName:#"BIDViewController" bundle:nil];
[self willAnimateRotationToInterfaceOrientation:view1.interFaceOrientaion1 duration:1];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
lable1.frame=CGRectMake(100 ,102 ,225 , 21);
[self setInterFaceOrientaion2:toInterfaceOrientation];
}
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
lable1.frame=CGRectMake(250, 116,225 ,21);
[self setInterFaceOrientaion2:toInterfaceOrientation];
}
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
lable1.frame=CGRectMake(250, 116, 225, 21);
[self setInterFaceOrientaion2:toInterfaceOrientation];
}
}
#end
BIDViewController class could be able to access the property interFaceOrientation2,
But BIDViewController2 class could not be able to access the property interFaceOrientation
thought #class BIDViewController is present.
how to access this.
Instead of calling properties change as per below
Check orientation as below in viewWillApear method
UIInterfaceOrientation orientation=[[UIApplication sharedApplication] statusBarOrientation];
[self willAnimateRotationToInterfaceOrientation:orientation duration:1];
I have following Controllers, (I have selected all types orientation modes in iPad)
Here is my iPad Storyboard layout
Custom NavigationController > Loading Ctrl > Main Controller.
My Custom Navigation Contains
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
In my Loading Controller
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
The supportedInterfaceOrientations gets called as usual and everything seems ok, But when I push my Main Controller using performSegue
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
No more calls in MainController. Why is that?
There is one trick.
Fetch the status bar from the Application and rotate it.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
Create and display and dismiss an empty view controller modally.
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
Now your device shoud have been forced to rotate. You could now segue to a proper view controller or push one using the navigation controller.
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);//choose portrait or landscape
}
- (BOOL) shouldAutorotate{
return NO;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;//choose portrait or landscape, same as above
}
Ever since updating my device to 6.1, I'm getting a crash when trying to show the UIImagePickerController. I only use Portrait orientation.
The Crash:
Reason: * Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
Here is where I call the UIImagePickerController:
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//The device cannot make pictures
[PMAlertDialog showWithTitle:NSLocalizedString(#"incompatibleDeviceDialogTitle", nil) message:NSLocalizedString(#"incompatibleDeviceDialogMessage", nil) andButtonTitle:NSLocalizedString(#"okButtonTitle", nil)];
return;
}
if (_imagePicker == nil)
{
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
}
_imagePicker.allowsEditing = NO;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:_imagePicker animated:YES];
I've added these methods to the view controller where the UIImagePickerController is added:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
To fix the issue, I made a category as follows:
I created a new objective-c class, "UIImagePickerController+NonRotating"
In the header file (UIImagePickerController+NonRotating.h):
#import <Foundation/Foundation.h>
#interface UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
#end
In the implementation file (UIImagePickerController+NonRotating.m):
#import "UIImagePickerController+NonRotating.h"
#implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
#end
You could of course modify this however you see fit -- making it autorotate and returning multiple supported orientations, etc.
I am trying to develop an app in XCode that will switch to a new view upon rotation.
Here is the code for view1controller.h:
#import UIKit/UIKit.h
#interface TestViewController : UIViewController {}
IBOutlet UIView *portrait;
IBOutlet UIView *landscape;
#property(nonatomic,retain) UIView *portrait;
#property(nonatomic,retain) UIView *landscape;
#end
and here is the code for view1controller.m:
#import "view1controller.h"
#implementation TestViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
self.view = landscape;
} else if (((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))) {
self.view = portrait;
}
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#synthesize portrait,landscape;
#end
Anyway so the app opens but it crashes upon opening.
Try something like:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = landscapeleft;
}
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = portraitupsidedown;
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = landscapeleft;
}
return YES;
}
Your brackets in your header are misplaced.
#interface TestViewController : UIViewController {
IBOutlet UIView *portrait;
IBOutlet UIView *landscape;
}
#property(nonatomic,retain) UIView *portrait;
#property(nonatomic,retain) UIView *landscape;
#end
Also, #synthesize portrait,landscape; needs to go under #implementation TestViewController
#implementation TestViewController
#synthesize portrait,landscape;
Notice the UIView's in this image:
I would do the following:
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
[portrait removeFromSuperview];
[self.view addSubview:landscape];
} else if (((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))) {
[landscape removeFromSuperview];
[self.view addSubview:portrait];
}
Hope this helps!