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

时间:2011-05-11 11:22:16

标签: iphone objective-c ipad ios4 quicklook

我有QuickLook(QLPreviewController)几乎按照我想要的方式工作,但由于图像特征我不希望它旋转成纵向。我在“shouldAutoRotateToInterfaceOrientation”方法中配置它只返回yes for landscape旋转(请参阅下面的代码了解详细信息)但它仍在旋转为纵向。

注意: 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 个答案:

答案 0 :(得分:5)

AppDelegate.m 替换

  

返回UIInterfaceOrientationMaskAll;

  

返回UIInterfaceOrientationMaskLandscape;

就像这样:

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

答案 1 :(得分:2)

根据ViewController Programming Guide for iOS,自动旋转大致由最近可见的ViewController控制。

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

所以自转旋转是由shouldAutorotateToInterfaceOrientation:的{​​{1}}方法控制的,在我的一个小实验中,它似乎允许除了倒置方向之外的所有方法。

所以你可以做的是定义一个QLPreviewController的子类,它只会覆盖你在QLPreviewController中所做的方式shouldAutorotateToInterfaceOrientation:并使用这个子类而不是原始的DocumentViewer

LandscapeOnlyQLPreviewController.h:

QLPreviewController

LandscapeOnlyQLPreviewController.m:

#import <QuickLook/QuickLook.h>

@interface LandscapeOnlyQLPreviewController : QLPreviewController {
}
@end

答案 2 :(得分:1)

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

但我还在寻找。

答案 3 :(得分:-1)

试试这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
相关问题