display problem in UIView iPad - iphone

I have a small application ipad, portrait mode is locked in the application,
The problem occurs when I turn down the IPAD, the display of the application is not running down
Can someone help me??

You should implement below method in all of your viewControllers.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait)
{
return YES;
}
return NO;
}
Hope this help.

Related

how can i turn keyboard in iOS6.0?

i have a portrait view (status bar hidden), but i turned it. Then keyboard shows this:
i want keyboard to turn and fullscreen. Please help me. Thanks in advance.
I have seen the comments.
You can't make the screen be landscape like this. IOS 6 has something new, "the app's appDelegate always start as portrait"
You should use the IOS 6 autorotate!
This should be in the appDelegate:
- (NSUInteger)application:(UIApplication*)application
supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return (UIInterfaceOrientationMaskAll);
}
In your view controller:
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
in the supportedInterfaceOrientations you can set it to landscape only

Orientation issue in XCode 4.5.2 GM Seed version with iOS 6

I am working on iPhone application with both Portrait orientations support (Portrait and Portrait UpsideDown).
In earlier XCode4.5.1, I have resolved this issue by:
Setting rootViewController in AppDelegate
Mentioning shouldAutorotateToInterfaceOrientation like this:
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation); }
Mentioning supportedInterfaceOrientation in info.plist file
Now I am doing the same things for newer XCode but in iPhone simulator v6.0 its not supporting rotation properly.
I have tried with these methods as well:
-(BOOL) shouldAutorotate {
BOOL returnValue = NO;
int interface = [self preferredInterfaceOrientationForPresentation];
if(UIInterfaceOrientationIsPortrait(interface)) {
// Code to handle portrait orientation
returnValue = YES;
}
else {
// Code to handle Landscape orientation
returnValue = NO;
}
return returnValue;
}
- (NSUInteger) supportedInterfaceOrientations {
return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return (UIInterfaceOrientationPortrait |
UIInterfaceOrientationPortraitUpsideDown);
}
Please guide me how to support both the Portrait orientations for iOS > 4.3 all the versions.
Thanks in advance,
Mrunal
Why Did Orientation Change to Landscape Stop Working in iOS 6?
Starting in IOS 6.0 there are several orientation changes that stopped my app from rotation out of Portrait.
The fix for me, and the one applicable here, is that you must setRootViewController on the window in your AppDelegate. The earlier answer offers several suggestions that are all correct, but misses the one item that was relevant for me.
In application didFinishLaunchingWithOptions, after:
[window makeKeyAndvisible]
or
[window addSubview: viewController.view];
You must replace with:
if([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
[window setRootViewController:viewController];
} else {
[window addSubview: viewController.view];
(or [window makeKeyAndvisible])
}
You also need to add the new shouldAutoRotate instead of the depreciated shouldAutorotateToInterfaceOrientation, but this was easier to find and less crucial for me.
Same with making sure all your orientations are specified in your .plist file.
I did not need to override supportedInterfaceOrientations because I am satisfied with the default orientations (all for iPad UIInterfaceOrientationMaskAll, all but upside-down for iPhone UIInterfaceOrientationMaskAllButUpsideDown).
I have to admit, that when iOS 6 came around, I fiddled around with this until I got something to work, and then stopped. But, here is my guess:
I believe that shouldAutorotate is intended to be used in situations when you might want to dynamically change whether or not your app supports autorotation at all. I don't think it's intended for you to tell iOS which orientations you support (like the original shouldAutorotateToInterfaceOrientation: method). So, if your app supports any autorotation, I think you should just do this:
-(BOOL) shouldAutorotate {
return YES;
}
supportedInterfaceOrientations is where you are supposed to identify which orientations you support.
However, in that method, you're doing that differently than what I've been using (which might, or might not be a problem). I think you should use the mask constants, for this method. So, instead of this:
- (NSUInteger) supportedInterfaceOrientations {
return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
}
use this:
- (NSUInteger) supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Also, I don't think the preferredInterfaceOrientationForPresentation method is supposed to return more than one orientation. Preferred should probably just be one, such as:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Here is the relevant Apple documentation
Update:
The other thing you might try is using this method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
in your App Delegate class. This method is optional, but can set the default values for which orientations your app supports, in case you don't specify them in all your View Controllers, or in the app's plist file. Since you don't show your plist file, and your other View Controllers, I can't tell if this might help, or not. But, it might be something to try.

Game center login lock in landscape only in i OS 6

When Game center is loaded its default orientation is portrait.
In order to lock it in landscape mode, added a category.
#implementation GKMatchmakerViewController (LandscapeOnly)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return NO;
}
#end
It is working fine in below iOS 6 .But in iOS6 it shows an error.
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
Please explain a solution.
At last i avoided crash by following the workaround mentioned in Apple's iOS 6 release notes.
Workaround:
1.Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
2. When a UIBNavigationController (or a UIViewController) is involved, subclass the UINavigationController/UIViewController and overriding supportedInterfaceOrientations.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
And
In buid summary supported orientations selected landscape right and landscape left.
Now game center is working properly without crash.
Have to add 1 little thing. Struggling with that stupid issue about 2 days. If above doesn't help and you have UINavigationController invovled (and you already did subclass it) you need the following (in appDelegate):
[window setRootViewController:navigationController]; // use this
// instead of [self.window addSubview:navigationController.view];
thanx 2 http://grembe.wordpress.com/2012/09/19/here-is-what-i/

auto-rotation in iOS5/6?

I updated to Xcode 4.5 and am working with iOS6--a mistake I will definitely not make next time there's an update; it's been sort of nightmarish for somebody so new to iOS--and I've just noticed an app I'm working on is autorotating. I never noticed it autorotatin before the update, but it's also possible I just didn't rotate the phone while testing, so I can't be sure. I've added the following code to the main UIViewController and it's still rotating:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
Is this the right way to disable autorotation? If it is, then maybe there's some change in iOS6 and I'll have to wait until the full release to find out. But if I've gotten it wrong, what code should I use instead?
Thanks, as always, for your help.
EDIT: Here's the code I changed it to, but it's still rotating. Have I gotten it wrong?
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else
{
return NO;
}
}
that is because there was never a success. You should choose one of the orientations.
Hold command and click on UIInterfaceOrientation you will see an enumeration of the possible options.
then you can test against those to decide your YES Scenario.
I may have originally misunderstood your problem. It seems that you may have been saying that your app is allowing rotation. but the code should disallow that.
I was thinking you were saying it was still firing the code. Trying to find a Yes
One thing to think about. is there may be more than one view controller available. perhaps your code is not being hit.
A couple of possible issues for this.
Your code is not even being used. because the view is being allocated as UIViewController as opposed to your custom view controller.
You code is being used but that View controller is not the one being asked about the Orientation. therefore that specific code is not being hit.
A bad build keeps putting the wrong assemblies onto the device.
Your solutions can be as follows.
Ensure your code is the one being allocated. Either there is a direct alloc on your custom class. or the xib file is inflating it. Check out the Identity Inspector when you have your xib file open. select your View Controller and ensure that custom class is set to your class type
Look at the hierarchy. what other view controllers are there. Perhaps one of those are telling the app it can autorotate to any orientation.
Find your "DerivedData" folder and remove it entirely. Sometimes this works from the organizer. other times you need to delete directly off the disk. Then clean and build again.
Also another solution could be as simple as setting the settings in the Project file.
Select your project file from the file browser and you will see the iPad and iPod settings in the summary. You can "UnPress" buttons for the orientations that you want to disallow. and any view controllers that you do not otherwise code orientation into. will use these by default.
My apologies for the confusion.
Update
I commonly use this code to handle my autorotation.
It not only differentiates the ipad from the other ios devices, but it also forwards the request onto presented controllers so a view that is shown modal may respond how it wants.
Orientation is a pain when you dont understand it :)
// Detect iPad
#define IS_IPAD() ([[UIDevice currentDevice] respondsToSelector:#selector(userInterfaceIdiom)] ? \
[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad : NO)
// Set preferred orientation for initial display
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
if (IS_IPAD()){
return UIInterfaceOrientationLandscapeRight;
}
else {
return UIInterfaceOrientationPortrait;
}
}
// Return list of supported orientations.
- (NSUInteger)supportedInterfaceOrientations{
if (self.presentedViewController != nil){
return [self.presentedViewController supportedInterfaceOrientations];
}
else {
if (IS_IPAD()){
return UIInterfaceOrientationMaskLandscapeRight;
}
else {
return UIInterfaceOrientationMaskAll;
}
}
}
// Determine iOS 6 Autorotation.
- (BOOL)shouldAutorotate{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
// Return yes to allow the device to load initially.
if (orientation == UIDeviceOrientationUnknown) return YES;
// Pass iOS 6 Request for orientation on to iOS 5 code. (backwards compatible)
BOOL result = [self shouldAutorotateToInterfaceOrientation:orientation];
return result;
}
// handle iOS 5 Orientation as normal
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Return YES for supported orientations
if (self.presentedViewController != nil){
return [self.presentedViewController shouldAutorotate];
}
else {
if (IS_IPAD()){
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
}
Rotation APIs have changed in iOS6. The new API's are apparently supposed to be opt in however they seem to be enabled for all debug builds on simulator or device. To register for the new API calls throw something like this in your APP Delegates didFinishLoading method.
//Register for new API rotation calls
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"UIApplicationSupportedInterfaceOrientationsIsEnabled"];
At the heart of the rotation changes are two methods (theres a third but Im still figuring this out myself)
- (BOOL)shouldAutorotate
- (NSUInteger)supportedInterfaceOrientations
You need to override these methods in your windows rootViewController. This means you need to subclass UINavigationController or UITabBarController if either is your root controller (this seems bizarre to me, but Apple says Jump).
Now if all you want to do is keep your app in portrait implement the two methods and you're golden.
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Note that apple has further added to the confusion by adding interface orientation masks, ie. UIInterfaceOrientationMaskPortrait != UIInterfaceOrientationPortrait. If you return UIInterfaceOrientationPortrait instead the behaviour will be different. Also you can combine masks the same way you combine orientations so if you wanted to support both portrait orientations you could use.
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
That should work for forcing a portrait orientation. Now if you if you want do do something like allow a child controller to use a different orientation I have no clue.
A very simple way to handle autorotation in both iOS6 and iOS5 is to use supportedInterfaceOrientations & shouldAutorotateToInterfaceOrientation. There are some macros to make it just a line of code. UIInterfaceOrientationIsLandscape & UIInterfaceOrientationMaskLandscape.
I discovered UIInterfaceOrientationMaskLandscape & UIInterfaceOrientationMaskPortrait by auto-completion in xCode. It is not in the Apple docs about autorotation.
Add this code block to your root ViewController to force it to support only landscape mode.
//iOS6 code to support orientations
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskLandscape);
}
//iOS5 code to support orientations
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return (UIInterfaceOrientationIsLandscape(orientation));
}
For iOS6 you can use the following to detect orientation:
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskAllButUpsideDown
UIInterfaceOrientationMaskAll
For iOS5 and below you can use the following to detect orientation:
UIInterfaceOrientationIsLandscape (A macro)
UIInterfaceOrientationIsPortrait
UIInterfaceOrientationIsLandscapeRight
UIInterfaceOrientationIsLandscapeLeft
UIInterfaceOrientationIsPortraitUpsideDown

orientation incorrectly reported in viewDidLoad

So I have an app that needs to load a different image as the background image depending on the orientation of the device. I have the following code in viewDidLoad:
BOOL isLandScape = UIDeviceOrientationIsLandscape(self.interfaceOrientation);
if (isLandScape)
{
self.bgImage.image = [UIImage imageNamed:#"login_bg748.png"];
}
For some reason even if the simulator starts in landscape this bool is still false. I checked and it always reports being in portrait mode regardless of the actual simulator orientation. Does anyone have an idea as to why this is not working?
In shouldAutoRotateForInterfaceOrientation I have the following:
if (UIDeviceOrientationIsLandscape(interfaceOrientation))
{
self.bgImage.image = [UIImage imageNamed:#"login_bg748.png"];
} else
{
self.bgImage.image = [UIImage imageNamed:#"login_bg1004.png"];
}
return YES;
And this code does work, its just the startup that is messed up. After I perform one rotation it works fine.
The reason is that viewDidLoad is too early. Every app launches in portrait and later rotates to landscape. When viewDidLoad is called, the rotation has not happened yet. You want to use delayed performance, or put your tests in didRotateFromInterfaceOrientation or similar. See the explanation in my book:
http://www.apeth.com/iOSBook/ch19.html#_rotation
First in the functionshouldAutoRotateForInterfaceOrientation you just have to return YES
now use this function
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view login
}
else
{
//portrait View logic
}
}
And if you are already in landscape view or portrait view then in your viewDidLoad function
-(void)viewDidLoad
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view code
}
else
{
//portrait view code
}
}
hope this will help