I want to make my appliaction only in landscape orientation in ios (Both ios 5 and ios 6)

百般思念 提交于 2019-12-28 06:25:13

问题


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!!


回答1:


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.




回答2:


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




回答3:


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!




回答4:


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)); }


来源:https://stackoverflow.com/questions/12933089/i-want-to-make-my-appliaction-only-in-landscape-orientation-in-ios-both-ios-5-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!