Disable Portrait interface in iOS 6 - uiinterfaceorientation

In my UIViewController
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL) shouldAutorotate {
return NO;
}
I should only support Landscape orientation in iOS 6. But it didn't work. It still working auto rotation.
How to fix disable autorotate in iOS 6 ?

Found a solution.
I am using viewcontroller with UINavigationController. So, I need to change supportedInterfaceOrientations in UINavigationController.
#interface UINavigationController (autorotate)
#end
#implementation UINavigationController (autorotate)
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL) shouldAutorotate {
return YES;
}
#end

If your entire app will only support landscape, you can just skip the subclass and set your supported interface orientations to Landscape (left) and Landscape (right) in Info.plist

Related

How can I make CSS hover effect touch screen friendly in Angular applications?

I have a pop up sign-in box which is shown when a person hover over the particular icon. How can I make it touch screen friendly in the Angular application?
This is the logic from my component:
private isPopupDisplayed: boolean = false;
mouseOver(event) {
this.isPopupDisplayed = true;
// console.log(`mouseOver ${this.isPopupDisplayed}`);
}
mouseLeave(event) {
this.isPopupDisplayed = false;
// console.log(`mouseLeave ${this.isPopupDisplayed}`);
}

Orientation management in UINavigationController in iOS 10

I have a very simple app, 3 UIViewControllers in UINavigationController:
I wish the first 2 UIViewControllers to work only in portrait orientation and the last one to work only in landscape one.
I subclassed UINavigation controller and I overrided three methods:
class NavCtrl: UINavigationController {
override var shouldAutorotate: Bool {
return topViewController?.shouldAutorotate ?? super.shouldAutorotate
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return topViewController?.supportedInterfaceOrientations ?? super.supportedInterfaceOrientations
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return topViewController?.preferredInterfaceOrientationForPresentation ?? super.preferredInterfaceOrientationForPresentation
}
}
In my first two view controllers I added:
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
In my last view I have:
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
When I run the app all 3 views support only portrait orientation, my last view doesn't work in landscape.
I put breakpoints to shouldAutorotate and supportedInterfaceOrientations (UINavigationController) but there are called only once when the app loads and again when I rotate device but not when the view controller is pushed to nav controller.
I tried to add this line:
UIViewController.attemptRotationToDeviceOrientation()
to viewDidLoad to my last view controller to force orientation reload but with no luck.
Do you have any idea I could make my app to match my requirements?
Thanks

ios 6.0 - Landscape not working - subclassed UINavigationController never calls shouldAutorotate method

I have created a simple application which has a red background and a button on it (for the purposes of understanding this problem). The app is in landscape mode and being built with iOS6 framework.
I have set the Supported interface orientations pList properties to only have: Landscape (right home button)
If I put the methods -(BOOL)shouldAutorotate and -(NSUInteger)supportedInterfaceOrientations in the view controller and initiate it as the windows rootViewController WITHOUT using a UINavigationController then landscape orientation is achieved.
HOWEVER if I use a subclassed UINavigationController like in the example below and implement -(BOOL)shouldAutorotate and -(NSUInteger)supportedInterfaceOrientations , landscape orientation is NOT achieved and -(BOOL)shouldAutorotate is never called.
I have the following code in my Subclassed UINavigationController:
//For iOS 5.x and below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationLandscapeRight);
}
//For iOS 6.0
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
-(BOOL)shouldAutorotate
{
return YES;
}
In my appDelegate I have these methods:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
viewController = [[MDViewController alloc] init]; //a very simple viewcontroller containing button on red background which should be in landscape mode
navigationController = [[MDNavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navigationController.topViewController];
[self.window makeKeyAndVisible];
return YES;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow: (UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeRight;
}
I have seen countless answers to similar questions which I implemented but found that they fail to work.
Thanks.
Shouldn't you be doing this:
[self.window setRootViewController:navigationController];
instead of:
[self.window setRootViewController:navigationController.topViewController];

iOS 6 UITabBarController supported orientation with current UINavigation controller

I have an iPhone app I am updating to iOS 6 that is having rotation issues. I have a UITabBarController with 16 UINavigationCotrollers. Most of the subviews can work in portrait or landscape but some of them are portrait only. With iOS 6 things are rotating when they shouldn't.
I tried subclassing the tabBarController to return the supportedInterfaceOrienations of the current navigationController's selected viewController:
- (NSUInteger)supportedInterfaceOrientations{
UINavigationController *navController = (UINavigationController *)self.selectedViewController;
return [navController.visibleViewController supportedInterfaceOrientations];
}
This got me closer. The view controller won't rotate out of position when visible, but if I am in landscape and switch tabs the new tab will be in landscape even if it isn't supported.
Ideally the app will only be in the supported orienation of the current visible view controller. Any ideas?
Subclass your UITabBarController overriding these methods:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
Subclass your UINavigationController overriding these methods:
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
Then implement these methods in your viewControllers that you do not want to rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
And for viewControllers that you do want to rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
Your tabbarController should be added as the RootviewController of the app window. If you plan to support the default orientations, all but upsidedown is default for iPhone, then you do not need to do anything else. If you want to support upside-down or if you do not want to support another of the orientations, then you need to set the appropriate values in app delegate and/or info.plist.
I had issue that some View controllers in the navigation stack support all the orientations, some only portrait, but UINavigationController was returning all app supported orientations, this little hack helped me. I'm not sure if this is intended behavior or what
#implementation UINavigationController (iOS6OrientationFix)
-(NSUInteger) supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
#end
I think is better something like that (as a category method)
-(NSUInteger) supportedInterfaceOrientations {
if([self.topViewController respondsToSelector:#selector(supportedInterfaceOrientations)])
{
return [self.topViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
this ensures that the method is implemented. If you aren't doing this check and the method is not implemented (like in iOS5 env) the app should crash!
If you plan to enable or disable rotation for all view controllers you don't need to subclass UINavigationController.
Instead use:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
in your AppDelegate.
If you plan to support all orientations in your app but different orientations on PARENT View Controllers (UINavigationController stack for example) you should use
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
from AppDelegate in combination with the following methods in your PARENT View Controller.
- (BOOL)shouldAutorotate
and
- (NSUInteger)supportedInterfaceOrientations
But if you plan to have different orientation settings in different CHILDREN ViewControllers in the same navigation stack (like me) you need to check the current ViewController in the navigation stack.
I've created the following in my UINavigationController subclass:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
int interfaceOrientation = 0;
if (self.viewControllers.count > 0)
{
DLog(#"%#", self.viewControllers);
for (id viewController in self.viewControllers)
{
if ([viewController isKindOfClass:([InitialUseViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else if ([viewController isKindOfClass:([MainViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else
{
interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return interfaceOrientation;
}
Since you cannot control anymore from children ViewControllers the rotation settings of presented view controller you must somehow intercept what view controller is currently in the navigation stack. So that's what I did :). Hope that helps !

Cannot make UIPopover appear programmatically

I want the pop-over to appear when the app is first launched in portrait mode instead of it being hidden and requiring the user to hit the button before the popover appears. I've tried to find solutions through the likes of Google and other StackOverflow threads, but I have not been able to figure it out. So in the event the standard SplitView sample that is created by XCode is different I'll put the code below. If I can make it work on this app I'm hoping that I can understand it and be able to apply it elsewhere.
I thought about trying to just call what is called when the button is pushed... but I can't figure out what is called and where it is declared... I feel like I'm overlooking something basic and it's driving me bananas!
The DetailView Controller
DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
UIPopoverController *popoverController;
UIToolbar *toolbar;
id detailItem;
UILabel *detailDescriptionLabel;
}
#property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
#property (nonatomic, retain) id detailItem;
#property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
#end
DetailViewController.m
#import "DetailViewController.h"
#import "RootViewController.h"
#interface DetailViewController ()
#property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
#end
#implementation DetailViewController
#synthesize toolbar, popoverController, detailItem, detailDescriptionLabel;
#pragma mark -
#pragma mark Managing the detail item
/*
When setting the detail item, update the view and dismiss the popover controller if it's showing.
*/
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
// Update the view.
[self configureView];
}
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView {
// Update the user interface for the detail item.
detailDescriptionLabel.text = [detailItem description];
}
#pragma mark -
#pragma mark Split view support
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
barButtonItem.title = #"Root List";
NSMutableArray *items = [[toolbar items] mutableCopy];
[items insertObject:barButtonItem atIndex:0];
[toolbar setItems:items animated:YES];
[items release];
self.popoverController = pc;
}
// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
NSMutableArray *items = [[toolbar items] mutableCopy];
[items removeObjectAtIndex:0];
[toolbar setItems:items animated:YES];
[items release];
self.popoverController = nil;
}
#pragma mark -
#pragma mark Rotation support
// Ensure that the view controller supports rotation and that the split view can therefore show in both portrait and landscape.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
#pragma mark -
#pragma mark View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.popoverController = nil;
}
#pragma mark -
#pragma mark Memory management
/*
- (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)dealloc {
[popoverController release];
[toolbar release];
[detailItem release];
[detailDescriptionLabel release];
[super dealloc];
}
#end
The rootview is a typical UITableViewController and is nothing special, but if for some reason you need that or the delegate (which is pretty boring minus loading the views) to help me figure out this problem I have no problems posting those also. Again this is straight up what XCode generates when I tell it I want to create a split view for the iPad and I have not modified it.
Hopefully there is something very minor I'm overlooking and it will make me smack my head and say "I can't believe I missed that!" Thanks for your help.
Figured it out!
I put
[self.popoverController presentPopoverFromBarButtonItem:[[toolbar items] objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
in the ViewDidLoad method. I knew it was something pretty simple! It seems to work without any problems!

Resources