iOS - QLPreviewController - 如何阻止 QuickLook 旋转?
我的 QuickLook (QLPreviewController) 几乎按照我想要的方式工作,但由于图像特征,我不希望它旋转为纵向。我在“shouldAutoRotateToInterfaceOrientation”方法中配置它,仅对横向旋转返回 yes(请参阅有关详细信息,请参阅下面的代码)但它仍然旋转为纵向。
注意: 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
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) 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在AppDelegate.m中替换
和
就像这样:
In AppDelegate.m replace
with
just like this:
根据 iOS 的 ViewController 编程指南,自动旋转大致由最近可见的 ViewController 控制。
在您的情况下,这可能是
QLPreviewController
本身,而不是您的DocumentViewer
。 (而且你说后者的shouldAutorotateToInterfaceOrientation:
没有被调用,这与这个假设一致)。因此,自动旋转是由
QLPreviewController
的shouldAutorotateToInterfaceOrientation:
方法控制的,在我的一个小实验中,该方法似乎允许除颠倒方向之外的所有方向。因此,您可以做的是定义
QLPreviewController
的子类,它仅重写shouldAutorotateToInterfaceOrientation:
就像您在DocumentViewer
中所做的那样,并使用此子类而不是原始的QLPreviewController
。LandscapeOnlyQLPreviewController.h:
LandscapeOnlyQLPreviewController.m:
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 yourDocumentViewer
. (And you say that the latter'sshouldAutorotateToInterfaceOrientation:
isn't called, which is consistent with this hypothesis).So the autorotation is controlled by the
shouldAutorotateToInterfaceOrientation:
method ofQLPreviewController
, 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 overridesshouldAutorotateToInterfaceOrientation:
the way you did inDocumentViewer
and use this subclass instead of the originalQLPreviewController
.LandscapeOnlyQLPreviewController.h:
LandscapeOnlyQLPreviewController.m:
我从来没有找到一个好的答案,所以我最终只使用了 UIWebView。
但我仍在寻找。
I never did find a good answer, so I ended up just using a UIWebView.
But I'm still looking.
试试这个:
Try this: