My supports both Landscape & Portrait mode in ios6. I also try with new methods of device rotation, But the methods are not called & it does not support the orientation.
My code is as follow:
-(NSUInteger)supportedInterfaceOrientations
{
NSLog(#"supportedInterfaceOrientations...");
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate
{
NSLog(#"shouldAutoRotate...");
return YES;
}
I don't know the issue for this.
Thanks...
Try this,
Because You Mentioned : Deployment target is ios5 but you run the app in ios6.
In .pch File,
#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )
And In Controller File, Check with Conditions,
#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return toInterfaceOrientation;
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskAll);
}
#endif
Hopefully, It will be helpful to you.
Thanks.
Do you support all Interface Orientations in the Target respectively in the Info.plist
You would need to check all these images to support all Orientations
Related
I have an iPhone 5 and an iPhone 4s that I am testing an xcode project on. I deleted my app on the iPhone 5 and re-built it and now it recognizes the iphone 5 as an iphone 4. I have tried both
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
NSLog(#"screen size is %f", screenSize.height);
if (screenSize.height > 480.0f) {
return TRUE;
} else {
return FALSE;
}
}
and
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_IPHONE ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: #"iPhone" ] )
#define IS_IPOD ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: #"iPod touch" ] )
#define IS_IPHONE_5 ( IS_IPHONE && IS_WIDESCREEN )
The problem is that somehow [UIScreen mainScreen]bounds.size.height is recognizing my screen height as 480.00000 not 586. Has anyone encountered this error and how do i fix it?
You must have a Default-568h#2x.png image in your code for it to recognize the proper screen height otherwise it will always be FALSE. I had accidentally deleted this image in between builds so it never tested properly.
By using Xcode4.5 i developed universal app, i want to make iPad version only in Landscape mode.
Here i have tired
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
return YES;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
return YES;
}
return NO;
}
Even though i have tried like the above code , it did appear in Portrait mode.
are you testing this in ios5 or ios6? In ios6 the shouldAutoRotate method is ignored. You need to use
-(NSUInteger) supportedInterfaceOrientations {
}
and
-(BOOL) shouldAutoRotate {
}
You can find more info on that here: iOS 6 auto rotate confusion
I have use the Xcode 4.5.1 and use this conditions
#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )
#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
[image_signature setImage:[self resizeImage:image_signature.image]];
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
[image_signature setImage:[self resizeImage:image_signature.image]];
return UIInterfaceOrientationMaskLandscapeLeft;
}
#endif
I have add the key in info.plist.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
And set the support interface orientation
IF i have add the key in info.plist and set the support orientation and no use the below code , application is not work in ios 5.0
This code is work but i want to use small alternative concept....Please help me..
Thanks in advance!!
Your approach is not healthy. The preprocessor blocks will only get compiled if #ifdef statements are true. What you have done is to make the preprocessor statements depend on runtime parameters.
You can try removing all preprocessor blocks. Make your deployment target 5.0.
Edit: FYI, these methods are callback methods so they will get called by system if needed. iOS5 will call shouldAutorotateToInterfaceOrientation method likewise iOS6 will call supportedInterfaceOrientations and iOS6's rotation methods accordingly. So you should handle all your system differences on runtime, not compile-time, unless you are compiling two different versions of app for two different systems on purpose.
Thanks MR. basar...i solve my problem ...I explain How to solve my problem....
If you set orientation in your app In IOS 5 and IOs 6
then folllow the step
1) Go to project -> select support Interface Orientations
Example :- You want to select Landscape Left and Landscape Right .. See the image
2) When you select Orientations then automatically add the key in info.plist (check in info.plist ) if no add then you add the key in info.plist
Example:-
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
3) add the code in each viewcontroller
// For IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
[image_signature setImage:[self resizeImage:image_signature.image]];
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
// For IOS 6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
[image_signature setImage:[self resizeImage:image_signature.image]];
return UIInterfaceOrientationMaskLandscapeLeft;
}
Note:-
1) No Need the condition (IOS Version) ...Because Both shouldAutorotateToInterfaceOrientation (IOs 5) supportedInterfaceOrientations (IOS 6) are delegate and it's call runtime...(see basar answer).
2) if you work only IOS 6 then no need the code. only work with step1 and step 2
There is another way - without setting allowed orientation:
Try this solution - it works on iOS 5 and iOS 6.
UINavigationController Force Rotate
Then, You can implement shouldRotate .. delegate methods, to allow it to rotate only between landscape orientations.
Good luck!
remove those preprocessors blocks and add this
to support autorotations in both ios5 and ios6 we need to provide call backs in case of ios6....`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
and we need to call
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutoRotate{
return YES;
}
for ios5
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)); }
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to force a screen orientation in specific view controllers?
hello
I want to set the orientation in one particular view so how can i do that. andbody have example for that. i used the
-(void)onUIDeviceOrientationDidChangeNotification:(NSNotification*)notification{
UIViewController *tvc = self.navigationController.topViewController;
UIDeviceOrientation orientation = [[ UIDevice currentDevice ] orientation ];
tabBarController.view.hidden = YES;
// only switch if we need to (seem to get multiple notifications on device)
if( orientation != [[ UIApplication sharedApplication ] statusBarOrientation ] ){
if( [ tvc shouldAutorotateToInterfaceOrientation: orientation ] ){
[ self rotateInterfaceToOrientation: orientation ];
}
}
}
but its done is whole application and i want to done only in one screen so please reply
thank you
on a particula view controller put
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
this is for potrait for other u can do like wise
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// Over ride this method in your required view controller to display only in the necessary orientation
}
Add this method in your class
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// Over ride this method in your required view controller to display only in the necessary orientation
return YES;
}
I'm building a cocos2d game which is supposed to be in portrait mode. I changed the RootViewController.m to portrait mode, and everything works fine, both on the simulator and on my iPad. However, when I run the game on my iPhone, it defaults back to landscape mode.
Any ideas on how to fix this?
Thanks.
I have a better solution that will work 100%:
Replace all the stuff that was in the RootViewController.m /
shouldAutorotateToInterfaceOrientation Method with following:
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
And if I ever want to change the orientation during runtime / switching scene:
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
Note that Auto Rotation is now on longer supported
in GameConfig.h:
use the director for autorotation
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationCCDirector
instead of
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationUIViewController
and in the AppDelegate.m
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
Inside the RootViewController return false from the method below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return false;
// other code...
}
In RootViewController.m
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
change this line to
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
in GameConfig.h:
For 1st and 2nd generation devices, value is set to kGameAutorotationNone, change it to kGameAutorotationUIViewController.
// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone