xcode iOS6 orientation landscape - xcode

I see a lot of questions about this subject but am unable to find a solution to the problem I am experiencing. I have created an iPad app that should be Landscape only - it works fine when ran on any os prior to iOS6 but on iOS6 the app opens in portrait view. This screenshot shows what I mean (sorry not a great explanation) http://s1342.beta.photobucket.com/user/designedbyria/media/ScreenShot2012-11-02at122113.png.html
I'm guessing the problem is somewhere in the below code, but I can't be sure. I have set the supported Interface Orientations to Landscape Left and Landscape Right only - but this has not worked. I have also taken a look at the questions here with no luck..
I am using xcode and cordova/phonegap
Interface orientation in iOS 6.0
Set orientation to landscape mode in xcode 4.5 GM IOS 6
iOS 6 apps - how to deal with iPhone 5 screen size?
Thanks in Advance!
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
/
- (BOOL) application:(UIApplication)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString]; NSLog(#"iwill launchOptions = %#", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == UIInterfaceOrientationLandscapeLeft) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
for (NSNumber *orient in self.viewController.supportedOrientations) {
if ([orient intValue] == curDevOrientation) {
forceStartupRotation = YES;
break;
}
}
}
if (forceStartupRotation) {
NSLog(#"supportedOrientations: %#", self.viewController.supportedOrientations);
// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0]
intValue];
NSLog(#"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES; }

I had the same problem (but not using cordova/phonegap).
You have to set your view controller as a RootViewController in your appDelegate instead of just adding as a subview.
Replace in you appdelegate:
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
By
[self.window setRootViewController:self.viewController];
[self.window makeKeyAndVisible];

You can use the delegate
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
Using this delegate and the application will be present in Landscape mode or any desired orientation mode.
Try it.

Related

DUXCameraSettingsController seems to be broken in UXSDK 4.8.x

After upgrading to the 4.8.x SDK from 4.7.1 the DUXCameraSettingsController stopped displaying the actual settings panels, but continues to show the settings tab-bar, pressing the tabs does not make any settings appear. Is this a bug in the UXSDK or am I just using the controller wrong? I cannot find any example on the usage of that particular controller.
- (UIView *)view
{
UIView *view = [UIView new];
DUXCameraSettingsController *ctrl = [DUXCameraSettingsController cameraSettingsController];
ctrl.view.translatesAutoresizingMaskIntoConstraints = NO;
ctrl.view.frame = view.frame;
[view addSubview:ctrl.view];
[ctrl.view.topAnchor constraintEqualToAnchor:view.topAnchor].active = YES;
[ctrl.view.bottomAnchor constraintEqualToAnchor:view.bottomAnchor].active = YES;
[ctrl.view.leadingAnchor constraintEqualToAnchor:view.leadingAnchor].active = YES;
[ctrl.view.trailingAnchor constraintEqualToAnchor:view.trailingAnchor].active = YES;
[ctrl didMoveToParentViewController:nil];
return view;
}

How to present a semi-transparent (half-cut) viewcontroller in iOS 8

in iOS 7 there is no problem for this method:
_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];
But in iOS 8 it did nothing.How to solve it? Is it a Bug for iOS 8?
My answer is more simple, below code. This works in iOS8 (XCode6 GM seed).
HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];
Note this workaround was needed on xcode6_beta7. The lastest xcode6
has the UIModalPresentationOver* styles fixed. So, I'm just assigning them to myModalViewController.modalPresentationStyle and now it works ok.
Finally made it work in iOS 8 after reading the UIPresentationController help and this post
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
MyModalController *myModalController = [[MyModalController alloc] initWithNibName:#"MyModalController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myModalController];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.transitioningDelegate = myModalController;
[self.navigationController presentViewController:navController animated:YES completion:nil];
You can make the modal view controller inherit from UIViewControllerTransitioningDelegate
#interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>
and override presentationControllerForPresentedViewController:...
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
if (presented == self) {
return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
} else {
return nil;
}
}
returning an instance of TransparentPresentationController which inherits from UIPresentationController
#interface TransparentPresentationController : UIPresentationController
and overrides shouldRemovePresentersView
- (BOOL) shouldRemovePresentersView {
return NO;
}

iOS 7: Restrict device current orientation when modal view controller is presented

I have a UIViewController which contains a UICollectionView. On tapping any of the UICollectionViewCell I present a modal view controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PopViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"DetailsView"];
vc.view.backgroundColor = [UIColor clearColor];
vc.transitioningDelegate = self;
vc.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:vc animated:YES completion:nil];
The PopViewController shows up correctly. Now I want to restrict the device orientation when PopViewController is being presented. That is if PopViewController is presented in portrait mode then it should not change to landscape even if I switch to landscape mode (using Rotate Left or Right in simulator) until I dismiss the PopViewController.
I have used following code in PopViewController:
-(BOOL)shouldAutorotate {
return NO;
}
What else (or instead) is needed to lock the pop up view to the current orientation?
in your modal controller try to add this, also (iOS > 6)
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
to support iOS 5 or below you must additional add:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

How do I develop for the iPad mini with Cordova/Phonegap?

I want to develop for the iPad Mini, but the simulator doesn't come with the Xcode 4.5. Is there any way I can see what my app is going to look like on the new iPad Mini? I am using the Cordova framework.
There is a simulator - it's called the iPad simulator. The iPad mini has the same resolution as the iPad. The only difference is the pixel density - i.e. the iPad mini has a greater pixel density than the iPad.
Go to your AppDelegate.m file and replace it with the code here:
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
//
// AppDelegate.m
// YOUR PROJECT NAME HERE
//
// Created by YOUR NAME HERE
// Copyright YOUR NAME HERE 2012. All rights reserved.
//
#import "AppDelegate.h"
#import "MainViewController.h"
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVURLProtocol.h>
#else
#import "CDVPlugin.h"
#import "CDVURLProtocol.h"
#endif
#implementation AppDelegate
#synthesize window, viewController;
- (id) init
{
/** If you need to do any extra app-specific initialization, you can do it here
* -jm
**/
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[CDVURLProtocol registerURLProtocol];
return [super init];
}
#pragma UIApplicationDelegate implementation
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString];
NSLog(#"YOUR PROJECT NAME HERE launchOptions = %#", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == curDevOrientation) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
for (NSNumber *orient in self.viewController.supportedOrientations) {
if ([orient intValue] == curDevOrientation) {
forceStartupRotation = NO;
break;
}
}
}
if (forceStartupRotation) {
NSLog(#"supportedOrientations: %#", self.viewController.supportedOrientations);
// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0] intValue];
NSLog(#"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
self.window.transform = CGAffineTransformConcat(scaleTransform, self.window.transform);
self.window.clipsToBounds = YES;
[self statusBarChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(statusBarChanged:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
return YES;
}
- (void)statusBarChanged:(NSNotification *)note {
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:#"statusBarWindow"];
statusBarWindow.transform = CGAffineTransformConcat(scaleTransform, statusBarWindow.transform);
}
- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:(#selector(doMagicToKeyboard)) withObject:nil afterDelay:0];
}
-(void)doMagicToKeyboard {
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
[self checkForKeyboard:window];
}
}
- (void)checkForKeyboard:(UIView *)view {
static BOOL didIt = NO;
for (UIView *currentView in view.subviews) {
if(([[currentView description] hasPrefix:#"<UIKeyboard"] == YES) && !didIt)
{
didIt = YES;
UIView *thisView = currentView.superview.superview;
thisView.clipsToBounds = YES;
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
thisView.transform = CGAffineTransformConcat(scaleTransform, thisView.transform);
} else {
[self checkForKeyboard:currentView];
}
}
}
// this happens while we are running ( in the background, or from within our own app )
// only valid if Ipad Mini-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
if (!url) {
return NO;
}
// calls into javascript global function 'handleOpenURL'
NSString* jsString = [NSString stringWithFormat:#"handleOpenURL(\"%#\");", url];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
return YES;
}
- (void) dealloc
{
[super dealloc];
}
#end
This will help people who want to develop for the iPad Mini; giving them a chance to see exactly what their app will look like on the new iPad Mini. This would not be possible without the great article I read on Michael Slaters blog. Here's the post where he walked me through the process of doing this for Cordova applications. Thanks Michael!
http://blog.michaelslater.net/making-your-ipad-app-mini.html?fb_comment_id=fbc_396351297103051_3342141_397114960360018#f35ee51728

How get auto rotate in iPad?

In my application i added UITabBarController *rootController;
in didFinishLaunchingWithOptions i done this code.
for that i wrote
WaylistController *waylistNavigationControllerTemp = [[WaylistNavigationController alloc] initWithNibName:#"WaylistNavigationController" bundle:nil];
self.waylisyViewController = waylistNavigationControllerTemp;
UINavigationController * waylistNavigationController = [[UINavigationController alloc] initWithRootViewController:waylisyViewController];
[waylistNavigationControllerTemp release];
WayRoomController *wayRoomNavigationControllerrTemp = [[WayRoomNavigationController alloc] initWithNibName:#"WayRoomNavigationController" bundle:nil];
self.WayRoomViewController = wayRoomNavigationControllerrTemp;
UINavigationController * wayRoomNavigationController = [[UINavigationController alloc] initWithRootViewController:WayRoomViewController];
[wayRoomNavigationControllerrTemp release];
rootController.viewControllers = [NSArray arrayWithObjects: WaylistNavigationController,//0
WayRoomNavigationController,//1
nil]
[rootController setSelectedIndex:0];
for this i am not getting auto orient always getting patriot only. any one please help me?
Put this in your controller class to which you need the orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) || (interfaceOrientation == UIInterfaceOrientationLanscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
return YES;
}
Also make sure that in your project setting you have enabled all the orientations.
In your .xib file use the autosizing to scale for both orientations.
Check Settings in .plist file for Supported interface orientation..

Resources