应用程序会在第二个显示屏上显示内容。问题是,当我旋转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
答案 0 :(得分:3)
shouldAutorotateToInterfaceOrientation:
是一种UIViewController
方法。应用程序委托不使用该方法。您应该创建一个UIViewController
子类并将您的内容放在其视图中。您必须在视图上设置适当的autoresizingMasks
或在每次轮换时转发您的视图。
但是,如果您打算继续使用应用程序委托,则应使用UIDevice
单例生成有关您可以收听的方向更改的通知。