Max*_*sca 5 iphone portrait storyboard interface-orientation ios6
在iPhone模拟器和iPhone 3GS(iOS 6)上,我都无法将方向设置为纵向颠倒.我只有一个ViewController.我在其中添加了此代码:
-(BOOL) shouldAutorotate{
return YES;
}
-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortraitUpsideDown;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
我还将此添加到AppDelegate.m:
-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
我还检查了plist文件,两个方向都存在.在我的故事板上,在Simulated Metrics Orientation设置为Inferred.我在applicationDidFinishLaunchingWithOptions中什么都不做,除了返回YES.我刚刚在这个ViewController中添加了一个UIImageView.是否有可能使这个方向有效?
Bej*_*max 11
supportedInterfaceOrientations返回一个NSUInteger.它返回视图控制器支持的所有接口方向,即接口方向值的掩码.
您需要返回UIInterfaceOrientationMaskEnum中定义的值,如下所示:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7707 次 |
| 最近记录: |