在这段代码中:
NSArray *supportedOrientations = nil;
if( iPhone ) { // bool
supportedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
// one array element
}
else if( iPad ) { // bool
supportedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations~ipad"];
// returns nil
}
else {
NSLog(@"%@:%@ device type not identified", kClassName, kMethodName);
}
Run Code Online (Sandbox Code Playgroud)
如果设备是iPhone,则supportedOrientations具有该阵列.
如果是iPad,supportOrientations为零.
始终找到该文件,因此NSLog永远不会显示(通过调试器逐步确认).
使用文本编辑检查plist时,我看到:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Run Code Online (Sandbox Code Playgroud)
有关为什么会发生这种情况的任何想法?
在iOS模拟器版本4.3中运行.
我正在开发一款只适用于风景的应用.在那个应用程序中,我有一个功能,截取该特定屏幕的截图.我已经实现了这段代码
UIGraphicsBeginImageContext(self.view.window.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();;
imageView.transform = CGAffineTransformMakeRotation(3.0 * M_PI / 2.0);
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(imageView.image, nil, nil, nil);
Run Code Online (Sandbox Code Playgroud)
使用此代码,我以纵向模式获取我的应用程序的屏幕截图.我希望它在横向模式下.
我希望我的应用程序支持PortraitUpSideDown方向.我已经更改了info.p列表以反映这一点并尝试在一个视图上实现更改作为测试
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但观点没有回应.在应用响应之前,是否需要在所有视图上实现此功能?我需要更改Xib设置吗?
这是一个关于简单的UIInterfaceOrientation对象的返回值的一个相当基本的问题,我尝试这个代码:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
BOOL orientacion = interfaceOrientation;
return orientacion;
}
Run Code Online (Sandbox Code Playgroud)
并且转换是这样做的,所以我认为UIInterfaceOrientation对象等于boolean var ?? 是一个隐含的拼写错误或真正的UIInterfaceOrientation等于布尔值..
我正在使用xcode 4.5,我只需要在一个包含webview的viewController上启用接口方向.我该如何启用它.
- (BOOL)shouldAutorotateToInterfaceOrientation 似乎在iOS6中已弃用
如何在我的应用程序的每个视图控制器上禁用自动旋转?我希望每个视图/屏幕只能在纵向模式下查看,如果手机旋转,我不希望我的视图控制器转换到横向模式.我该怎么做呢?我在网上看到了太多令人困惑的解释/教程.我在特定的视图控制器上尝试了以下代码,它没有帮助,视图仍然旋转
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL) shouldAutorotate {
return YES;
}
Run Code Online (Sandbox Code Playgroud) 我有一个支持iPad和iPhone的通用应用程序。在iPad上,我支持所有方向;在iPhone上,我仅支持纵向。
我希望一个视图控制器(以模态显示)在iPhone上运行时能以设备所处的任何方向显示。我已经看到许多教程和SO帖子,建议使用-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window应用程序委托方法,这似乎可行关于旋转模态视图控制器绝对好。但是,当我在横向模式下关闭模式视图时,整个应用程序仍保持横向模式。
理想情况下,一旦取消模式视图,应用程序应回到纵向模式。
经过调查,似乎-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window在关闭视图控制器后未调用回调,而且我不知道为什么。
我在这里玩过示例应用程序,并且在关闭视图控制器时触发了回调,但我不知道为什么。我可以看到的唯一区别是我的视图层次结构要复杂得多,并且我显示的是导航控制器,而不是显式的视图控制器,但是我看不到这将如何影响回调。
有什么解决方案的想法吗?
谢谢
iphone objective-c uiinterfaceorientation modalviewcontroller ios
我目前正在使用UIViewController 的interfaceProperty ,该属性从 iOS 8 开始已被弃用。
@property(nonatomic,readonly) UIInterfaceOrientation interfaceOrientation NS_DEPRECATED_IOS(2_0,8_0);
Run Code Online (Sandbox Code Playgroud)
我使用所述属性来确定物理主页按钮的方向,以进行加速度计和重力矢量校正。UIDeviceOrientation 不是合适的替代品,因为这些更正实际上应用于用户界面。
我已经寻找了合适的重构建议,但是,它们不适用于我对该属性的使用。
我在网上搜索得很高,但是找不到明确的答案.UIViewController当嵌入在a中时UINavigationController,只有一种支持横向模式的最佳方法是UITabBarController什么?
像这样的大多数解决方案都建议压倒一切
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
Run Code Online (Sandbox Code Playgroud)
在AppDelegate.这有点工作,但是当从唯一ViewController支持横向模式返回时,所有其他(非横向ViewControllers)也将处于横向方向.他们没有保持纵向.
我已经看到应用程序正确,所以我知道它必须以某种方式.例如,电影播放器应用程序通常仅限于肖像,但实际的电影播放器视图以强制横向模式模式呈现.在解除模态视图控制器后,底层视图控制器仍然正确纵向,
任何提示?
objective-c uiviewcontroller uiinterfaceorientation ios landscape-portrait