iOS - QLPreviewController - 如何阻止QuickLook旋转?

问题描述 投票:5回答:4

我的QuickLook (QLPreviewController)几乎可以按照我想要的方式工作,但由于图像的特性,我不想让它旋转到纵向。我在 "shouldAutoRotateToInterfaceOrientation "方法中配置了它,只对横向旋转返回 "是"(详情请看下面的代码),但它仍然在旋转到纵向。

注意:在 "shouldAutoRotateToInterfaceOrientation "方法中,只对横向旋转返回 "是"(详见下面的代码),但它仍在旋转为纵向。 shouldAutoRotateToInterfaceOrientation方法是直接复制的,在这个项目中我的所有视图控制器中都使用了该方法,而且在其他视图控制器中也能正常工作。

//
//  documentViewer.m
//

#import "DocumentViewer.h"

@implementation DocumentViewer

@synthesize documents;

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    else 
        return NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

//-(void)viewWillAppear:(BOOL)animated {
//  
//  self.userInteractionEnabled = YES;
//}

//Nessary for Enabling User Interaction
- (BOOL)canBecomeFirstResponder {
    return YES;
}

-(void) createList:(NSString *) document {

    documents =     [[NSArray arrayWithObjects:document, nil] retain];
}

-(NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {

    return [documents count];
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {

    return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[documents objectAtIndex:index] ofType:nil]];
}
@end
iphone objective-c ipad ios4 quicklook
4个回答
5
投票

在"... AppDelegate.m 替换

返回UIInterfaceOrientationMaskAll。

返回UIInterfaceOrientationMaskLandscape。

就像这样。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskLandscape;
}

2
投票

根据 iOS的ViewController编程指南视图控制器(ViewController)是最近才变得可见的,自动旋转大致由它控制。

在你的情况下,这可能是 QLPreviewController 本身,而不是你 DocumentViewer. (你还说后者的 shouldAutorotateToInterfaceOrientation: 并没有被调用,这与这个假设是一致的)。)

所以自动旋转是由 shouldAutorotateToInterfaceOrientation: 方式 QLPreviewController在我的一个小实验中,除了倒立的方向之外,似乎什么都允许。

所以,你可以做的是定义一个子类的 QLPreviewController 覆盖 shouldAutorotateToInterfaceOrientation: 如同 DocumentViewer 并用这个子类代替原来的 QLPreviewController.

LandscapeOnlyQLPreviewController.h。

#import <QuickLook/QuickLook.h>

@interface LandscapeOnlyQLPreviewController : QLPreviewController {
}
@end

LandscapeOnlyQLPreviewController.m:

#import "LandscapeOnlyQLPreviewController.h"

@implementation LandscapeOnlyQLPreviewController
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
  return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end

1
投票

我一直没有找到一个好的答案 所以我最后只用了一个UIWebView.

但我还在找。


-1
投票

试试这个。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
© www.soinside.com 2019 - 2024. All rights reserved.