开发者

iOS - QLPreviewController - How to stop QuickLook from Rotating?

I have QuickLook (QLPreviewController) almost working how I want it, but because of the images characteristics I don't want it to rotate into portrait orientation.I have it configured in the "shouldAutoRotateToInterfaceOrientation" method to only return yes for landscape rotations (see code below for details) but it is still rotating to portrait.

Note: The shouldAutoRotateToInterfaceOrientation is a direct copy that is used in all of my view controllers for this project and it is working in the other view controllers.

//
//  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) createL开发者_运维知识库ist:(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


In AppDelegate.m replace

return UIInterfaceOrientationMaskAll;

with

return UIInterfaceOrientationMaskLandscape;

just like this:

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


According to the ViewController Programming Guide for iOS, the autorotation is roughly controlled by the ViewController that was most recently made visible.

In your case that's probably the QLPreviewController itself, not your DocumentViewer. (And you say that the latter's shouldAutorotateToInterfaceOrientation: isn't called, which is consistent with this hypothesis).

So the autorotation is controlled by the shouldAutorotateToInterfaceOrientation: method of QLPreviewController, which in a little experiment of mine seems to allow everything but upside-down orientation.

So what you can do is define a subclass of QLPreviewController that only overrides shouldAutorotateToInterfaceOrientation: the way you did in DocumentViewer and use this subclass instead of the original 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


I never did find a good answer, so I ended up just using a UIWebView.

But I'm still looking.


Try this:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜