5

我有 QuickLook (QLPreviewController) 几乎可以按我的意愿工作,但是由于图像特性,我不希望它旋转到纵向。我在“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
4

4 回答 4

5

AppDelegate.m中替换

返回 UIInterfaceOrientationMaskAll;

返回 UIInterfaceOrientationMaskLandscape;

像这样:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskLandscape;
}
于 2012-11-25T11:37:39.993 回答
2

根据iOS 的 ViewController Programming Guide,自动旋转大致由最近可见的 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
于 2011-05-16T20:49:36.760 回答
1

我从来没有找到一个好的答案,所以我最终只使用了 UIWebView。

但我还在寻找。

于 2011-08-03T20:32:11.873 回答
-1

试试这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
于 2011-05-11T20:22:59.543 回答