我有一个代码,其中所有 UI 项都是由动态创建的。我有一个导航控制器,它连接到主窗口的其他视图。在这我有一个问题,当我编写一个方向改变的代码时,它不会自动工作。
杂注标记 MainViewController
@implementation 主视图控制器
@synthesize 图像视图;@synthesize btnBegin, btnSite; @synthesize 电话号码;
- (void)viewDidLoad { self.title=@"Midwest Sleep Test";self.view.backgroundColor = [UIColor whiteColor];
CGRect myImageRect = CGRectMake(-10,-10,320,313);
imageView = [[UIImageView alloc] initWithFrame:myImageRect];
[imageView setImage:[UIImage imageNamed:@"midwestsleep.png"]];
[self.view addSubview:imageView];
[imageView release];
btnBegin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnBegin addTarget:self action:@selector(Begin:) forControlEvents:UIControlEventTouchUpInside];
[btnBegin setTitle:@"Begin!" forState:UIControlStateNormal];
btnBegin.frame = CGRectMake(112,295,95,45);
[self.view addSubview:btnBegin];
CGRect myLabelRect = CGRectMake(112,345,130,22);
phoneNumber=[[UILabel alloc] initWithFrame:myLabelRect];
phoneNumber.text=@"937-350-5645";
phoneNumber.textColor=[UIColor blueColor];
phoneNumber.font= [UIFont fontWithName:@"ComicSansMsBold" size:18];
[self.view addSubview:phoneNumber];
btnSite = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnSite addTarget:self action:@selector(Site:) forControlEvents:UIControlEventTouchUpInside];
[btnSite setTitle:@"www.midwestsleepmed.com" forState:UIControlStateNormal];
btnSite.frame = CGRectMake(1,370,320,22);
[self.view addSubview:btnSite];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation{
return YES;}
enter code-(IBAction)Begin:(id)sender{
SecondView *sV = [[SecondView alloc] init];
[self.navigationController pushViewController:sV animated:YES];
[sV release];}
`-(IBAction)Site:(id)sender{ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@" http://www.midwestsleepmed.com "]];}
杂注标记 AppDelegate
语用标记 -
@implementation MidWestSleepAppDelegate
@synthesize 窗口;@synthesize 视图控制器;@synthesize 分数;
- (void)applicationDidFinishLaunching:(UIApplication *)application{
LogMethod();
// If you want the status bar to be hidden at launch use this:
// application.statusBarHidden = YES;
//
// To set the status bar as black, use the following:
// application.statusBarStyle = UIStatusBarStyleBlackOpaque;
// Create window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// this helps in debugging, so that you know "exactly" where your views are placed;
// if you see "red", you are looking at the bare window, otherwise use black
// window.backgroundColor = [UIColor redColor];
viewController = [ [ MainViewController alloc ] init ];
navigationController = [ [ UINavigationController alloc ] initWithRootViewController: viewController ];
/* Anchor the view to the window */
[window addSubview:[navigationController view]];
/* Make the window key and visible */
[window makeKeyAndVisible];}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation{
return YES;}
@结尾
在上面的代码中,当我实现时,我在处于横向模式的模拟器中遇到问题,整个 uiview 变得不同并且没有得到自己的位置。这段代码有什么问题,我该如何解决?