【问题标题】:iOS Orientation IssuesiOS 方向问题
【发布时间】:2012-12-30 13:44:11
【问题描述】:

我有一个简单的网络应用程序,我使用本机构建。

我的 MainWindow.xlb 应用程序包含 Native View Controller。

在 Native View Controller.m 中,我有以下代码:

http://pastebin.com/xXFc0JCW

在这里复制粘贴看起来很乱。

我似乎无法理解我哪里出错了,为什么我的应用程序/UIWebView 总是保持纵向。

我是 iOS 开发新手。

完整源代码:https://www.dropbox.com/s/i9woti5ptecr9n4/Native.zip

【问题讨论】:

    标签: ios objective-c uiwebview orientation


    【解决方案1】:

    现在可以了:

    NativeAppDelegate.m

    #import "NativeAppDelegate.h"
    #import "NativeViewController.h"
    
    @implementation NativeAppDelegate
    
    @synthesize window;
    @synthesize viewController;
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
        // Override point for customization after app launch    
    
        [self.window setRootViewController:viewController];
    
        return YES;
    }
    
    
    - (void)dealloc {
        [viewController release];
        [window release];
        [super dealloc];
    }
    
    @end
    

    NativeViewController.m

    #import "NativeViewController.h"
    
    @implementation NativeViewController
    
    @synthesize webView;
    
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"login" ofType:@"html"];
        NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
    
    
        if (htmlData) {
            NSBundle *bundle = [NSBundle mainBundle]; 
            NSString *path = [bundle bundlePath];
            NSString *fullPath = [NSBundle pathForResource:@"login" ofType:@"html" inDirectory:path];
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]];
        }
    }
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [webView release];
        [super dealloc];
    }
    
    @end
    

    我还在 InterfaceBuilder 的 WebView 中取消选中 ScaleToFill,否则您必须滚动页面才能看到您的 hello world。

    我删除了定位方法并将 RootviewController 设置为您的 Window 到您的 ViewController。您的窗口没有 RootVieController。

    【讨论】:

    • 太好了,这似乎有效,谢谢...只是为了我的理解,我只是没有授予网络视图阅读 oritetnation 的权限吗?
    • 最大的问题是您的窗口没有 RootViewController 并将 WebView 添加为 SubView...但是没有 RootView。如果它现在有效,请将问题标记为已解决。
    【解决方案2】:

    坦率地说,我在您的代码片段中没有发现任何问题。然而,最近发生了变化,引入了 iOS6。如果我没记错的话,对于使用当前 SDK 构建的应用程序,将不再调用 shouldRotateToInterfaceOrientation 。取而代之的是,您在 info.plist 中定义支持的界面方向,并可能通过覆盖方法 supportedInterfaceOirentations 来覆盖视图控制器中的该设置,该方法返回整数中的位掩码(多么现代... :)

    来自文档:

    处理视图旋转 在 iOS 6 中,您的应用支持界面 在应用的 Info.plist 文件中定义的方向。一个视图控制器 可以覆盖supportedInterfaceOrientations方法来限制 支持的方向列表。一般系统调用这个 仅在窗口或视图的根视图控制器上的方法 控制器呈现以填满整个屏幕;子视图控制器 使用他们的父视图为他们提供的窗口部分 控制器,不再直接参与有关决策 支持哪些旋转。应用程序的交集 方向掩码和视图控制器的方向掩码用于 确定视图控制器可以旋转到哪些方向。

    如果我在这里错了,请纠正我。

    【讨论】:

    • 在我的 Native-Info.plist 中,我支持界面方向数组 4 项(移植和横向),并且与 ipad 的支持界面方向相同...但它仍然可以旋转,我可以看到实际的设备是由于状态栏但网页视图统计纵向
    猜你喜欢
    • 2014-11-28
    • 2013-05-24
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多