5

私は 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
4

4 に答える 4

5

AppDelegate.m置換

UIInterfaceOrientationMaskAllを返します。

UIInterfaceOrientationMaskLandscapeを返します。

ちょうどこのような:

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

ViewController Programming Guide for iOSによると、オートローテーションは、最近表示された ViewController によって大まかに制御されます。

あなたの場合、それはおそらくQLPreviewControllerそれ自体であり、あなたのものではありませんDocumentViewer。(そして、後者shouldAutorotateToInterfaceOrientation:は呼び出されないと言いますが、これはこの仮説と一致しています)。

そのため、オートローテーションは のshouldAutorotateToInterfaceOrientation:方法で制御されQLPreviewControllerます。私の小さな実験では、逆さまの向き以外はすべて許可されているようです。

したがって、できることは、元の の代わりにこのサブクラスを使用する方法をQLPreviewControllerオーバーライドするだけの のサブクラスを定義することです。shouldAutorotateToInterfaceOrientation:DocumentViewerQLPreviewController

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 に答える