iOS - QLPreviewController - Как остановить вращение QuickLook? - PullRequest
5 голосов
/ 11 мая 2011

У меня 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 ]

5 голосов
/ 25 ноября 2012

In AppDelegate.m replace

return UIInterfaceOrientationMaskAll;

с

return UIInterfaceOrientationMaskLandscape;

просто так:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskLandscape;
}
2 голосов
/ 17 мая 2011

Согласно Руководству по программированию ViewController для iOS , авторотация примерно контролируется 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 голос
/ 04 августа 2011

Я так и не нашел хорошего ответа, поэтому я просто использовал UIWebView.

Но я все еще ищу.

0 голосов
/ 12 мая 2011

Попробуйте это:

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