开发者

iOS Orientation: Tried this and tried that

The app will show stuff on a second display fine. Issue is when I when I rotate the iPad the content doesn't rotate on the iPad.

Have looked at:

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

Anyone who could tell me exactly what I need to add would be appreciated! :)

#import "iPadVGAOutputT开发者_StackOverflow中文版estAppDelegate.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: is a UIViewController method. The application delegate doesn't make use of that method. You should create a UIViewController subclass and put your content on its view. You will have to set appropriate autoresizingMasks on the view or relay your views on every rotation.

But if you intend to persist on using the application delegate, you should use the UIDevice singleton to generate notifications on orientation changes which you can listen to.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜