该应用程序将在第二个显示屏上很好地显示内容。问题是当我旋转iPad时,内容在iPad上不旋转。

看过:

http://developer.apple.com/library/ios/#qa/qa1688/_index.html
Interface Orientation won't change to Landscape on App Launch
iPhone SDK: Orientation (Landscape and Portrait views)
http://www.bytesizecreations.com/2009/05/working-with-orientation-changes-on/
iPhone app in landscape mode, 2008 systems
iPhone app in landscape mode, 2008 systems
http://www.iphonedevsdk.com/forum/iphone-sdk-development/7366-interface-builder-landscape-design.html#post186977

任何可以告诉我确切需要添加什么的人将不胜感激! :)

#import "iPadVGAOutputTestAppDelegate.h"

@implementation iPadVGAOutputTestAppDelegate

@synthesize deviceWindow;
@synthesize consoleTextView;
@synthesize externalWindow;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    externalWindow.hidden = YES;


    // Make iPad window visible.
    [deviceWindow makeKeyAndVisible];

    // Check for external screen.
    if ([[UIScreen screens] count] > 1) {
        [self log:@"Found an external screen."];

        // Internal display is 0, external is 1.
        externalScreen = [[[UIScreen screens] objectAtIndex:1] retain];
        [self log:[NSString stringWithFormat:@"External screen: %@", externalScreen]];

        screenModes = [externalScreen.availableModes retain];
        [self log:[NSString stringWithFormat:@"Available modes: %@", screenModes]];

        // Allow user to choose from available screen-modes (pixel-sizes).
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"External Display Size"
                                                         message:@"Choose a size for the external display."
                                                        delegate:self
                                               cancelButtonTitle:nil
                                               otherButtonTitles:nil] autorelease];
        for (UIScreenMode *mode in screenModes) {
            CGSize modeScreenSize = mode.size;
            [alert addButtonWithTitle:[NSString stringWithFormat:@"%.0f x %.0f pixels", modeScreenSize.width, modeScreenSize.height]];
        }
        [alert show];

    } else {
        [self log:@"External screen not found."];
    }

    return YES;
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIScreenMode *desiredMode = [screenModes objectAtIndex:buttonIndex];
    [self log:[NSString stringWithFormat:@"Setting mode: %@", desiredMode]];
    externalScreen.currentMode = desiredMode;

    [self log:@"Assigning externalWindow to externalScreen."];
    externalWindow.screen = externalScreen;

    [screenModes release];
    [externalScreen release];

    CGRect rect = CGRectZero;
    rect.size = desiredMode.size;
    externalWindow.frame = rect;
    externalWindow.clipsToBounds = YES;

    [self log:@"Displaying externalWindow on externalScreen."];
    externalWindow.hidden = NO;
    [externalWindow makeKeyAndVisible];
}


- (void)log:(NSString *)msg
{
    [consoleTextView setText:[consoleTextView.text stringByAppendingString:[NSString stringWithFormat:@"%@\r\r", msg]]];
}


- (void)dealloc
{
    [consoleTextView release];
    [deviceWindow release];
    [externalWindow release];

    [super dealloc];
}


@end

最佳答案

shouldAutorotateToInterfaceOrientation:UIViewController方法。应用程序委托不使用该方法。您应该创建一个UIViewController子类并将其内容放在其视图中。您将必须在视图上设置适当的autoresizingMasks或在每次旋转时中继视图。

但是,如果您打算继续使用应用程序委托,则应使用UIDevice单例生成有关可以监听的方向更改的通知。

09-25 15:51