如何在 UINavigationController 中的单个视图上强制使用特定的 UIInterfaceOrientation?

发布于 2024-11-08 20:54:34 字数 392 浏览 4 评论 0原文

好的,情况如下:

我有一个应用程序,我只希望 UINavigationController 中的一个特定视图具有横向方向。这个视图是一个 UIImageView,我正在其上捕获签名(该部分效果很棒)。所以,就像这样:

previous view --> signature view --> next view
 (portrait)        (landscape)       (portrait)

我似乎找不到一种好方法来强制设备方向在该签名屏幕上横向显示。在签名视图上采用纵向方向永远没有意义,因为在该屏幕宽度上确实没有足够的空间进行签名。

那么,关于如何实现这一目标有什么好主意吗?我考虑过可能以模态方式执行签名视图,从而突破导航控制器。想法?

Okay, so here's the situation:

I have an app in which I only want ONE specific view in a UINavigationController to have a landscape orientation. This view is a UIImageView that I'm capturing a signature on (THAT part works awesome). So, like this:

previous view --> signature view --> next view
 (portrait)        (landscape)       (portrait)

I can't seem to find a good way to force the device orientation to landscape on that signature screen. It'll never make sense to have a portrait orientation on the signature view because there's really not adequate room for signing in that screen width.

So, any bright ideas on how to accomplish this? I've considered possibly doing the signature view modally, thus breaking out of the navigation controller. Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

西瓜 2024-11-15 20:54:34

您可以尝试强制设备旋转到必要的方向 - 但您需要手动处理它(除了覆盖 UIViewController 方向处理方法之外)。

要旋转设备,您可以使用以下方法:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

但它可能不适用于所有情况...

也可用未记录的方法:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                       withObject:(__bridge id)((void*)UIInterfaceOrientationLandscapeLeft)];

You can try to force Device to rotate to necessary orientation - but you need to handle it manually (in addition to overriding UIViewController orientation handling methods).

To rotate device you can use next methods:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

But in it may not work in all situations...

Also available undocumented approach:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                       withObject:(__bridge id)((void*)UIInterfaceOrientationLandscapeLeft)];
止于盛夏 2024-11-15 20:54:34

只需重写此 UIViewController 方法,仅对横向返回 true,就像这样,iPhone 将被迫旋转到该设备方向,因为它没有其他选项。

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Just override this UIViewController method to only return true for landscape like so and the iphone will be forced to rotate to that device orientation, since it has no other option.

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
风情万种。 2024-11-15 20:54:34

不幸的是,导航控制器内的所有根 UIViewController 都必须支持其任何子方向。这意味着设置中的第一个视图控制器必须支持横向,否则子视图控制器将仅支持纵向。

实现您正在寻找的内容的最佳方法是创建一个 UIViewController,在旋转变换上显示其内容视图,并将该堆栈中的所有 UIViewController 默认为纵向。

Unfortunately, all root UIViewControllers inside of a Navigation Controller must support any of their child orientations. This means that the first view controller in your setup must support landscape, otherwise the child will only support portrait.

The best way to implement what you are looking for is to create a UIViewController that displays its content view on a rotated transform, and just default all UIViewControllers in that stack to portrait.

桜花祭 2024-11-15 20:54:34

我认为您可以将此视图嵌入视图控制器中并覆盖 ShouldRotateToInterfaceOrientation 方法。
祝你好运!

I think you can embed this view inside a view controller and overwrite the ShouldRotateToInterfaceOrientation method.
Good luck!

临走之时 2024-11-15 20:54:34

要仅在横向中使用视图,我在 ViewController 中有以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

To use a View in only landscape, I have the following in the ViewController:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
月依秋水 2024-11-15 20:54:34

这可能就是您所寻找的。

// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
self.view.transform = transform;

// Repositions and resizes the view.
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
self.view.bounds = contentRect;

来自 http://www.iphonedevsdk。 com/forum/iphone-sdk-development/1394-landscape-uiviewcontroller-uiview-rotation.html

This might be what your looking for.

// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
self.view.transform = transform;

// Repositions and resizes the view.
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
self.view.bounds = contentRect;

from http://www.iphonedevsdk.com/forum/iphone-sdk-development/1394-landscape-uiviewcontroller-uiview-rotation.html

随遇而安 2024-11-15 20:54:34

我有一个仅具有横向视图的应用程序,甚至从横向开始。这在 iOS 5.x 中工作正常,但在 iOS 6.x 中停止工作。

在尝试了很多事情(其中一些比其他事情更值得怀疑)之后,我找到了一个对我来说清晰且可预测的解决方案。

我做了几件事。

-- 我在 IB 中将视图保持为横向模式。

-- 我在项目设置中检查了两种横向模式 - 有四个图标可以控制它

-- iOS 6.x 中的方向管理已更改。我必须重写一些方法来支持更改横向

此方法适用于 iOS 5.x

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.
    return (interfaceOrientation & UIInterfaceOrientationMaskLandscape);
}

这 2 个方法适用于 iOS 6.x

- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger supportedOrientations = UIInterfaceOrientationMaskLandscape;
    return supportedOrientations;
}


- (BOOL)shouldAutorotate
{
    return YES;
}

- 但关键是更改 AppDelegate 中的逻辑。我的原始代码是向窗口添加一个子视图(controller.view)。这在 iOS 6.x 中停止工作 - 我更改了对 window.setRootController 的调用。这是最终的一步——如果不进行最后的改变,它就无法工作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
    //[self.window addSubview:viewController.view];
    [self.window setRootViewController:viewController];
    [self.window makeKeyAndVisible];


    return YES;
}

I have an app that has landscape only views that even starts in landscape. This was working fine in iOS 5.x but stopped working in iOS 6.x

After trying many many things, some more questionable than others, I found a solution that to me is clear and predictable.

I did several things.

-- I kept the views in landscape mode in IB.

-- I checked both landscape modes in the project settings - there a four icons there to control it

-- Orientation mgmt has changed in iOS 6.x. I had to overwrite a few methods to support changing to landscape

this method is for iOS 5.x

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.
    return (interfaceOrientation & UIInterfaceOrientationMaskLandscape);
}

these 2 methods are for iOS 6.x

- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger supportedOrientations = UIInterfaceOrientationMaskLandscape;
    return supportedOrientations;
}


- (BOOL)shouldAutorotate
{
    return YES;
}

-- But the key was to change the logic in the AppDelegate. Original code I had there was adding a subview (controller.view) to the window. This stopped working in iOS 6.x - I changed the call to window.setRootController. That was the final step that sealed it - it would not work without making this final change

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{        
    //[self.window addSubview:viewController.view];
    [self.window setRootViewController:viewController];
    [self.window makeKeyAndVisible];


    return YES;
}
失而复得 2024-11-15 20:54:34

UINavigationController 覆盖包含 UIViewController 方向设置,因此您必须使用以下 5.1 创建 UINavigationController 的自定义子类:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[self topViewController] isKindOfClass:[SigCaptureViewController class]]) {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    } else {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
}

对于 6.0 及更高版本,您需要:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if ([[self topViewController] isKindOfClass:[EXTRASigCaptureViewController class]]) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

我还没有弄清楚如何强制 UINavigationController 旋转。调用 [[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRightAnimated:NO] 会导致状态栏旋转,但不会导致视图旋转。

The UINavigationController overrides the contain UIViewController orientation settings, so you have to create a custom subclass of UINavigationController with the following for 5.1:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[self topViewController] isKindOfClass:[SigCaptureViewController class]]) {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    } else {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
}

For 6.0 and above you need:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if ([[self topViewController] isKindOfClass:[EXTRASigCaptureViewController class]]) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

What I haven't figured out is how to make the force the UINavigationController to rotate. calling [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO] causes the status bar to rotate but doesn't cause the view to rotate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文