该应用程序将在第二个显示器上正常显示内容。问题是当我旋转 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];
} khác {
[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];
}
@kết thúc
shouldAutorotateToInterfaceOrientation:
是一个 UIViewController
方法。应用程序委托(delegate)不使用该方法。您应该创建一个 UIViewController
子类并将您的内容放在它的 View 上。您必须在 View 上设置适当的 autoresizingMasks
或在每次旋转时传递您的 View 。
但如果您打算坚持使用应用程序委托(delegate),您应该使用 UIDevice
单例来生成您可以收听的方向变化通知。
Tôi là một lập trình viên xuất sắc, rất giỏi!