Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

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

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. enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...